@hyperfrontend/ui-utils/time

time

Animation-frame–based pause and timestamp formatting helpers.

pause(ms) returns a promise that resolves after the requested duration, scheduled via requestAnimationFrame so the wait stays in sync with the browser's render cycle and is automatically suspended when the tab is backgrounded. timestampToDateTime formats a millisecond timestamp into a human-readable date-time string suitable for log lines, debug overlays, and UI labels that prefer a stable, locale-independent shape.

API Reference

ƒ Functions

§function

pause(timeMS: number): Promise<void>

Creates a promise that resolves after the specified delay, useful for pausing execution.

Parameters

NameTypeDescription
§timeMS
number
The delay in milliseconds

Returns

Promise<void>
A promise that resolves after the specified time

Example

Implementing retry with backoff

async function fetchWithRetry(url: string, maxRetries: number) {
  for (let attempt = 0; attempt < maxRetries; attempt++) {
    try {
      return await fetch(url)
    } catch {
      await pause(1000 * Math.pow(2, attempt)) // Exponential backoff
    }
  }
}
§function

timestampToDateTime(timestamp: number): string

Converts a Unix timestamp to a formatted date-time string.

Parameters

NameTypeDescription
§timestamp
number
The Unix timestamp in milliseconds

Returns

string
A formatted date-time string in the user's locale with UTC timezone

Example

Formatting timestamp

timestampToDateTime(1704067200000)
// => 'Mon, 01/01/2024, 00:00:00 UTC' (varies by locale)