Skip to content

Commit

Permalink
Merge pull request #397 from LIT-Protocol/feature/lit-2654-js-sdk-fix…
Browse files Browse the repository at this point in the history
…-utc-calculation-on-expiration

fix: calculation should be UTC now instead of executor's now
  • Loading branch information
Ansonhkg authored Mar 12, 2024
2 parents 3322946 + 5c902f2 commit 883d7c4
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/contracts-sdk/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,19 @@ export function convertRequestsPerDayToPerSecond(
// Calculates the expiration timestamp in UTC for a given number of days from now.
// The expiration time is set to midnight (00:00:00) UTC of the target day.
export function calculateUTCMidnightExpiration(daysFromNow: number): number {
// Create a Date object for the current time in UTC
const now = new Date();
const futureDate = new Date(
const utcNow = Date.UTC(
now.getUTCFullYear(),
now.getUTCMonth(),
now.getUTCDate() + daysFromNow
now.getUTCDate()
);

// Create a future Date object in UTC, adding the specified number of days
const futureDate = new Date(utcNow);
futureDate.setUTCDate(futureDate.getUTCDate() + daysFromNow);
futureDate.setUTCHours(0, 0, 0, 0); // Set to midnight UTC

return Math.floor(futureDate.getTime() / 1000);
}

Expand Down

0 comments on commit 883d7c4

Please sign in to comment.