Skip to content

Instantly share code, notes, and snippets.

@ypcode
Created March 7, 2020 22:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ypcode/98ead1fc491e3fe88031eaeed5812d29 to your computer and use it in GitHub Desktop.
Save ypcode/98ead1fc491e3fe88031eaeed5812d29 to your computer and use it in GitHub Desktop.
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