1 time
ztimson edited this page 2024-09-22 03:11:09 -04:00

@ztimson/utils / time

time

Functions

formatDate()

formatDate(date): string

Return date formated highest to lowest: YYYY-MM-DD H:mm AM

Parameters

date: string | number | Date

Date or timestamp to convert to string

Returns

string

Formated date

Defined in

src/time.ts:7


sleep()

sleep(ms): Promise<void>

Use in conjunction with await to pause an async script

Parameters

ms: number

Time to pause for in milliseconds

Returns

Promise<void>

  • Resolves promise when it's time to resume

Example

await sleep(1000) // Pause for 1 second

Defined in

src/time.ts:28


sleepUntil()

sleepUntil(fn, checkInterval): Promise<void>

Sleep while function returns true

Parameters

fn

Return true to continue

checkInterval: number = 100

Run function ever x milliseconds

Returns

Promise<void>

Callback when sleep is over

Example

let loading = true;
setTimeout(() => wait = false, 1000);
await sleepUntil(() => loading); // Won't continue until loading flag is false

Defined in

src/time.ts:46


timeUntil()

timeUntil(date): number

Calculate the number of milliseconds until date/time

Parameters

date: number | Date

Target

Returns

number

  • Number of milliseconds until target

Defined in

src/time.ts:56