Files
UT-Registration-Plus/src/shared/util/time.ts
doprz 8a6e9070e0 chore: lint-format-docs-tests-bugfixes (#105)
* docs: add jsdoc

* feat: change enums to as const objects

* chore(test): add themeColors.test.ts

* fix: fix tests and bugs with strings.ts util

* fix: path alias imports and tsconfig file bug

* fix: remove --max-warnings 0
2024-03-06 15:11:27 -06:00

22 lines
873 B
TypeScript

export const MILLISECOND = 1;
export const SECOND = 1000 * MILLISECOND;
export const MINUTE = 60 * SECOND;
export const HOUR = 60 * MINUTE;
export const DAY = 24 * HOUR;
/**
* Pauses the execution for the specified number of milliseconds.
* @param milliseconds - The number of milliseconds to sleep.
* @returns A promise that resolves after the specified number of milliseconds.
*/
export const sleep = (milliseconds: number): Promise<void> => new Promise(resolve => setTimeout(resolve, milliseconds));
/**
* Checks to see if expired by the time first stored and the time frame that it is stored for
*
* @param time time it was stored
* @param threshold time frame it can be stored for
* @return true if expired, false if the time frame is still in range
*/
export const didExpire = (time: number, threshold: number): boolean => time + threshold <= Date.now();