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.

44 lines • 2.6 kB
import { ExcelDateSystem } from "./toExcelSerial.js"; /** * Convert an Excel day serial back to an ISO 8601 instant string. * * - The serial is days with the time of day as the fraction, read as a UTC wall clock. * - **Serial 60 in the 1900 system returns ""** — it is the phantom 29 February 1900, a date * that never existed. Lotus 1-2-3 treated 1900 as a leap year and Excel keeps the bug for * compatibility, so the whole serial day `[60, 61)` is a hole: 59 is 1900-02-28 and 61 is * 1900-03-01. Mapping 60 to either neighbour would put every earlier date one day out. * - In the 1904 system serial 60 is a real 1904-03-01. * - Accepted range is Excel's own: serial 1 (1900-01-01) to just under 2958466 (the end of * 9999-12-31) in the 1900 system, serial 0 to just under 2957004 in the 1904 system. * Serial 0 in the 1900 system is Excel's "January 0, 1900" placeholder, not a date. * - Rounds to the nearest millisecond. A serial is a `double`, whose resolution is about a * microsecond near 2024 and about 40 µs near 9999 — finer than a millisecond nowhere in * the range, so rounding there is what makes the round trip through `toExcelSerial` exact. * - Returns "" on invalid input. * * @param value Excel day serial (number, may carry a fractional time of day) * @param options Which Excel date system the serial is in * @returns ISO 8601 instant string (UTC), or "" on invalid input * * @example fromExcelSerial(1) // "1900-01-01T00:00:00Z" — Excel's first serial * @example fromExcelSerial(25569) // "1970-01-01T00:00:00Z" * @example fromExcelSerial(45361.5) // "2024-03-10T12:00:00Z" * @example fromExcelSerial(59) // "1900-02-28T00:00:00Z" * @example fromExcelSerial(60) // "" — the phantom 1900-02-29, a date that never existed * @example fromExcelSerial(61) // "1900-03-01T00:00:00Z" * @example fromExcelSerial(60, { system: "1904" }) // "1904-03-01T00:00:00Z" — no phantom day here * @example fromExcelSerial(43899.5, { system: "1904" }) // "2024-03-10T12:00:00Z" * @example fromExcelSerial(0) // "" — Excel's "January 0, 1900", not a date * @example fromExcelSerial(-1) // "" */ export declare function fromExcelSerial(value: number, options?: { /** * Which Excel date system the serial is counted in. `"1900"` counts serial 1 as 1900-01-01 * and has the phantom serial 60; `"1904"` is the legacy Mac system, whose serial 0 is * 1904-01-01 and which has no phantom day. The same instant is exactly 1462 lower in the 1904 * system. * * @defaultValue `"1900"` */ system?: ExcelDateSystem; }): string;