-
-
Save ypcode/98ead1fc491e3fe88031eaeed5812d29 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const DEFAULT_SAFETY_WINDOW_IN_MSECS = 4860000; // 1h31 (Graph common delay is 4230 rounded minutes (70.5 h)) | |
export const getExpirationDateTimeISOString = (fromNowInDays: number, safetyWindowInMsecs?: number) => { | |
const now = Date.now(); | |
// day 24h 60m 60s ms | |
// const expiration = now + (fronNowInDays * 24 * 60 * 60 * 1000); | |
const expiration = now + (fromNowInDays * 86400000) - (safetyWindowInMsecs || DEFAULT_SAFETY_WINDOW_IN_MSECS); | |
return new Date(expiration).toISOString(); | |
}; | |
export const isNearlyExpired = (dateIsoString: string, safetyWindowInMsecs?: number) => { | |
const date = Date.parse(dateIsoString); | |
return (date - (safetyWindowInMsecs || DEFAULT_SAFETY_WINDOW_IN_MSECS)) <= Date.now(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment