UNPKG

@burglekitt/gmt

Version:

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

19 lines (18 loc) 745 B
import { parseUnitFromUnix } from "./parseUnitFromUnix.js"; /** * Return the year from a unix epoch value. * * - Delegates to {@link parseUnitFromUnix} with unit "year". * - Returns "" for invalid input. * * @param value unix epoch in milliseconds or seconds (number or string) * @param options optional: epochUnit ("seconds" | "milliseconds"), timeZone (IANA) * @returns Year (YYYY) or "" on invalid input * * @example parseYearFromUnix(1700000000000) // "2023" * @example parseYearFromUnix(1704067200000, { epochUnit: "milliseconds" }) // "2024" * @example parseYearFromUnix(-86400, { epochUnit: "seconds" }) // "1969" */ export function parseYearFromUnix(value, options) { return parseUnitFromUnix(value, "year", options); }