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.

38 lines • 1.87 kB
import { UnixUnit } from "../validate/isValidUnixUnit.js"; /** * Convert a Unix timestamp to a plain datetime string in the format "YYYY-MM-DDTHH:mm:ss". * * - Converts to PlainDateTime in `timeZone`. * - `value` is a safe integer or a string of optionally negative ASCII digits; anything else returns * "". * - Returns "" for invalid input. * * @param value Unix epoch: a safe integer or a digit string * @param options optional: how `value` is read and the zone its wall clock is read in * @returns plain datetime string in "YYYY-MM-DDTHH:mm:ss" format or "" on invalid input * * @example convertUnixToPlainDateTime(1709164800000, { timeZone: "UTC" }) // "2024-02-29T00:00:00" * @example convertUnixToPlainDateTime(1709164800, { epochUnit: "seconds", timeZone: "UTC" }) // "2024-02-29T00:00:00" * @example convertUnixToPlainDateTime(-1, { timeZone: "UTC" }) // "1969-12-31T23:59:59.999" * @example convertUnixToPlainDateTime("1709164800000", { timeZone: "Asia/Tokyo" }) // "2024-02-29T09:00:00" * @example convertUnixToPlainDateTime(NaN) // "" * @example convertUnixToPlainDateTime(45870000, { timeZone: "-00:44:30" }) // "1970-01-01T12:00:00" (a stored offset with seconds) */ export declare function convertUnixToPlainDateTime(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; /** * The time zone the wall-clock fields are read in: an IANA name, a UTC offset (a time zone * identifier such as `+05:30`, `+0530` or `-08`, or a stored offset `±HH:MM[:SS]`, what * `getTimeZoneOffset` returns), or `"local"` for the system time zone. An unknown zone returns * `""`. * * @defaultValue `"UTC"` */ timeZone?: string; }): string;