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.71 kB
/** The resolved options the readers need. */ export type FieldContext = Pick<Intl.ResolvedDateTimeFormatOptions, "calendar" | "timeZone" | "locale" | "hourCycle">; /** Forget the cached readers (the engine's `Intl.DateTimeFormat` was replaced). */ export declare function forgetFieldReaders(): void; /** * The date and time fields of an instant in a calendar and zone, read from the engine's own * calendar data: `era`, `year` (or `relatedYear`), `month`, `day`, `hour` (0 to 23), `minute`, * `second`. * * @example localFieldsOf({ calendar: "gregory", timeZone: "UTC", locale: "en", hourCycle: undefined }, 0)["year"] // "1970" */ export declare function localFieldsOf(resolved: FieldContext, ms: number): Record<string, string>; /** * The flexible day period the formatter prints for an instant, in its own width, or `""` when its * pattern prints none (so no two instants differ in it). The period is a property of the time as * the pattern prints it: with minutes, 12:00 is `noon` and 12:25 `in the afternoon`, while an * hour-only pattern says `noon` for the whole hour. So the reader carries the caller's own time * fields, and no date field (a week-year pattern could make a date field unsafe to read: D23). * * @example dayPeriodOf({ hour: "numeric", minute: "numeric", dayPeriod: "long" }, { calendar: "gregory", timeZone: "UTC", locale: "en", hourCycle: "h12" }, Date.UTC(2024, 6, 10, 12, 0)) // "noon" */ export declare function dayPeriodOf(options: Intl.DateTimeFormatOptions, resolved: FieldContext, ms: number): string; /** * Whether two instants hold equal field values in every Table 6 row ECMA-402 * PartitionDateTimeRangePattern checks, so the range is the start's single format. A row is * checked while no range pattern is selected, and from the first row the pattern prints until the * first later row it does not print (`checkMoreFields`): a month-only pattern ignores the day, a * pattern with minutes ignores the seconds. Printed text is never compared. * * @param options the formatter's options * @param resolved its resolved calendar, zone, locale and hour cycle * @param startMs the start in epoch milliseconds * @param endMs the end in epoch milliseconds * @param era whether the pattern prints an era (default: the `era` option is set) * @returns `true` when the range collapses to the start's single format * * @example rangeFieldsEqual({ year: "2-digit" }, { calendar: "gregory", timeZone: "UTC", locale: "en", hourCycle: undefined }, Date.UTC(1924, 0, 1), Date.UTC(2024, 0, 1)) // false */ export declare function rangeFieldsEqual(options: Intl.DateTimeFormatOptions, resolved: FieldContext, startMs: number, endMs: number, era?: boolean): boolean;