UNPKG

@northguild/gmt

Version:

Date and time library for JavaScript and TypeScript, built on TC39 Temporal: time zones, DST, business days, ISO 8601 strings in and out. Never throws.

30 lines • 1.39 kB
import { UnixUnit } from "../validate/isValidUnixUnit.js"; /** * Convert a unix epoch value to a UTC Instant ISO string. * * - Converts to UTC Instant using Temporal.Instant. * - `value` is a safe integer or a string of optionally negative ASCII digits; anything else, or an * instant outside the Temporal range, returns "". * - An explicit `undefined` `options` is the same as omitted; a non-object `options` (such as a * bare `"seconds"` string) returns "". * * @param value epoch value: a safe integer or a digit string * @param options optional: how `value` is read * @returns UTC Instant string or "" on invalid * * @example convertUnixToUtc(1709164800000) // "2024-02-29T00:00:00Z" * @example convertUnixToUtc(1709164800, { epochUnit: "seconds" }) // "2024-02-29T00:00:00Z" * @example convertUnixToUtc("1709164800", { epochUnit: "second" }) // "2024-02-29T00:00:00Z" * @example convertUnixToUtc(-1) // "1969-12-31T23:59:59.999Z" * @example convertUnixToUtc(1709164800, "seconds" as never) // "" (options must be an object) * @example convertUnixToUtc(NaN) // "" */ export declare function convertUnixToUtc(value: number | string, options?: { /** * The unit the epoch values are counted in: `"seconds"` or `"milliseconds"`, singular or * plural. Any other value returns `""`. * * @defaultValue `"milliseconds"` */ epochUnit?: UnixUnit; }): string;