@hyperfrontend/ui-utils/timetime
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
Creates a promise that resolves after the specified delay, useful for pausing execution.
Parameters
| Name | Type | Description |
|---|---|---|
§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
}
}
}Converts a Unix timestamp to a formatted date-time string.
Parameters
| Name | Type | Description |
|---|---|---|
§timestamp | number | The Unix timestamp in milliseconds |
Returns
stringA 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)