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.

35 lines • 1.61 kB
import { UnixUnit } from "../validate/isValidUnixUnit.js"; /** * Extract the date portion from a unix epoch value. * * - Converts to ZonedDateTime then extracts the PlainDate. * - Returns "" for invalid input. * * @param value unix epoch in milliseconds or seconds: a safe integer, or a string of optionally negative ASCII digits * @param options optional: how `value` is read and the zone its wall clock is read in * @returns ISO date string (e.g., "2024-03-17") or "" on invalid input * * @example parseDateFromUnix(1700000000000, { timeZone: "UTC" }) // "2023-11-14" * @example parseDateFromUnix(1700000000, { epochUnit: "seconds", timeZone: "UTC" }) // "2023-11-14" * @example parseDateFromUnix(-86400, { epochUnit: "seconds", timeZone: "UTC" }) // "1969-12-31" * @example parseDateFromUnix("1700000000000", { timeZone: "Asia/Tokyo" }) // "2023-11-15" (digit string) * @example parseDateFromUnix(1.5) // "" (not an integer epoch) */ export declare function parseDateFromUnix(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;