@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.
26 lines • 1.23 kB
TypeScript
interface ShiftableByDays<T> {
readonly calendarId: string;
withCalendar(calendar: "iso8601"): {
readonly year: number;
};
subtract(duration: {
days: number;
}): T;
}
/**
* Run `measure` on `source`, and when it throws because a boundary it builds lies after the last
* representable date, run it again on `source` shifted back by whole 400-year Gregorian cycles.
*
* - Use only for a quantity the cycle leaves unchanged: a length in days (or time) between
* boundaries of years, months or weeks. Never for a returned date.
* - Applies to Gregorian-structured calendars only; any other calendar rethrows the error.
* - A source already below `PROXY_FLOOR_YEAR` rethrows: its failure is not a max-edge one.
*
* @param source date or date-time whose surroundings are measured
* @param measure computes the quantity from a date in the same position of its cycle
* @returns the quantity, identical for `source` and its shifted proxy
*
* @example measureNearRangeEnd(Temporal.PlainDate.from("+275760-09-13"), (d) => d.until(d.with({ month: 10, day: 1 })).days) // 18
*/
export declare function measureNearRangeEnd<T extends ShiftableByDays<T>, R>(source: T, measure: (from: T) => R): R;
export {};