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.

58 lines • 3.3 kB
import { Temporal } from "./temporal.js"; import { ResolvedRelativeTo } from "./resolveDurationRelativeTo.js"; import { DurationRoundOptions, ZonedDifferenceOptions } from "./zonedDifference/operations.js"; import { plainDateUntilWithRounding } from "./zonedDifference/calendarArithmetic.js"; import { plainUntilWithRounding } from "./zonedDifference/nudgeWindow.js"; /** * Whether Temporal's DifferenceTemporalZonedDateTime would reject `largestUnit` for this pair: a * calendar unit (day or larger) between two different time zones (TimeZoneEquals is false), because * "day lengths can vary between time zones due to DST". TimeZoneEquals compares primary * identifiers, so `UTC` equals `Etc/UTC` and `Asia/Calcutta` equals `Asia/Kolkata` * (`timeZoneEquals`, temporalCompat D19). * * @param one the start * @param two the end * @param largestUnit the requested `largestUnit` * @returns true when the pair cannot be differenced in `largestUnit` */ export declare function isCalendarDifferenceAcrossZones(one: Temporal.ZonedDateTime, two: Temporal.ZonedDateTime, largestUnit: string): boolean; /** * `ZonedDateTime#until`, correct at the range limits (see the note at the top of this file). * * @param one the start * @param two the end * @param options Temporal `largestUnit` / `smallestUnit` / `roundingIncrement` / `roundingMode` * @returns the difference; throws where TC39 Temporal throws for the rounding options. A calendar * `largestUnit` across two time zones is not rejected here (TC39 DifferenceTemporalZonedDateTime * throws a RangeError): callers gate it with `isCalendarDifferenceAcrossZones`. */ export declare function zonedUntil(one: Temporal.ZonedDateTime, two: Temporal.ZonedDateTime, options?: ZonedDifferenceOptions): Temporal.Duration; /** * `Duration#total({ unit, relativeTo })`, correct at the range limits and in calendars the * polyfill gets wrong. * * @param duration the duration to total * @param unit the Temporal unit to total in * @param relativeTo Temporal `relativeTo`; a zoned one reaches the range-limit fallbacks, and a * zoned or plain one in a calendar that needs the compat layer takes the spec path * @returns the total; throws where TC39 Temporal throws */ export declare function durationTotal(duration: Temporal.Duration, unit: Temporal.TotalUnit<Temporal.DateTimeUnit>, relativeTo?: ResolvedRelativeTo): number; /** * `Duration#round(roundTo)`, correct at the range limits. * * @param duration the duration to round * @param roundTo Temporal round options; only a zoned `relativeTo` reaches the fallbacks * @returns the rounded duration; throws where TC39 Temporal throws */ export declare function durationRound(duration: Temporal.Duration, roundTo: DurationRoundOptions): Temporal.Duration; /** * `Temporal.Duration.compare(one, two, { relativeTo })`, correct at the range limits. * * @param one the first duration * @param two the second duration * @param relativeTo Temporal `relativeTo`; only a zoned one reaches the fallbacks * @returns -1, 0 or 1; throws where TC39 Temporal throws */ export declare function durationCompare(one: Temporal.Duration | string, two: Temporal.Duration | string, relativeTo?: ResolvedRelativeTo): number; export { plainDateUntilWithRounding, plainUntilWithRounding };