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.

39 lines • 2.33 kB
import { Temporal } from "../temporal.js"; import { FieldKey } from "./fieldSearch.js"; export type CalendarDateFields = FieldKey | { era: string; eraYear: number; month: number; day: number; }; /** * `Temporal.PlainDate.from({ ...fields, calendar: calendarId }, { overflow: "reject" })`, made * correct where `@js-temporal/polyfill` is not. * * The polyfill answers first, and its result is kept whenever its fields read back unchanged * through `calendarFieldsOf`. Only when it throws or reads back differently, for a defect the * installed runtime has (probed once per calendar) and inside that defect's range, does the * read-only field search answer instead: * * - **D1:** the polyfill's `calendarToIsoDate` probes outside the legacy `Date` range within about * a year of both limits and throws `Invalid ISO date` (hebrew, buddhist, islamic-*, persian, * indian). Retired by a js-temporal release porting proposal-temporal `a41eb67` + `af0cb4b`. * - **D2, D3, D4, D5:** the runtime's own reads are wrong (buddhist before 1582-10-15, Hebrew years * <= 0, Indian before ISO year 1), so its fields → ISO is too; the search runs over the * corrected reads. Retired with the read corrections in `calendarFields.ts`. * - **D8:** era codes that only the pre-proposal polyfill accepts (`japanese-inverse`) are * rejected, as a fixed runtime rejects them. * - **D10:** a polyfill porting proposal-temporal #3292 without the tc39/proposal-temporal#3329 fix * skips a 5- or 6-day month 13 (ethioaa, and so coptic and ethiopic) in far years. While its * probe fails, every year searches. Any throw other than a `RangeError` also searches, whatever * the probes say. * - **D18:** in WebKit the polyfill's conversion of an Islamic year <= 1 does not return or lands * in the mirror year, so for such a year the search answers without asking it * (`polyfillCannotReturn`); any other Islamic year that does not read back searches too. * * Era input is never searched: only "japanese" uses eras here, and it has no D1 window. * * @returns a PlainDate calendared as `calendarId`; throws RangeError for fields that do not name * an in-range date */ export declare function calendarDateFromFields(calendarId: string, fields: CalendarDateFields, overflow: "reject"): Temporal.PlainDate;