UNPKG

@burglekitt/gmt

Version:

Temporal-based date and time utilities with timezone support and polyfill integration

26 lines (25 loc) 1.3 kB
import type { DateTimeDurationUnit, Overflow } from "../../types/index.js"; /** * Add a temporal amount to a Unix epoch value and return the resulting epoch. * * - Converts to ZonedDateTime, adds the duration, then converts back to epoch. * - Validates duration units and values. * - Returns null for invalid input. * * `overflow` ("constrain" (default) | "reject") controls out-of-range results, e.g. adding 1 month * to Jan 31: "constrain" clamps to Feb 29/28, "reject" throws (resulting in null). * * @param value Unix timestamp (number) * @param units Partial<Record<DateTimeDurationUnit, number>> object specifying units to add * @param options optional: epochUnit ("seconds" | "milliseconds"), timeZone (IANA), overflow ("constrain" | "reject") * @returns Unix epoch number after addition, or null on invalid input * * @example addUnix(1706659200000, { days: 1 }) // 1706745600000 * @example addUnix(1706659200, { days: 1 }, { epochUnit: "seconds" }) // 1706745600 * @example addUnix(-86400000, { days: 1 }) // 0 (Dec 31 1969 + 1 day = Jan 1 1970) */ export declare function addUnix(value: number, units: Partial<Record<DateTimeDurationUnit, number>>, options?: { epochUnit?: "seconds" | "milliseconds"; timeZone?: string; overflow?: Overflow; }): number | null;