@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.
27 lines • 1.47 kB
TypeScript
import { Temporal } from "./temporal.js";
export interface LocaleWeekYearBounds {
weekYear: number;
/** Days from the source date to the first day of `weekYear`'s week 1 (0 or negative). */
startOffsetDays: number;
/** Days from the source date to the first day of `weekYear + 1`'s week 1 — exclusive (positive). */
endOffsetDays: number;
}
/**
* Resolve the locale week-numbering year `date` belongs to, and the
* `[start, end)` bounds of that week-year as day offsets from `date`, given a
* locale's `firstDay` (1 = Monday .. 7 = Sunday) and `minimalDays` (the
* minimum January days a week must have to count as week 1) — both from
* `Intl.Locale.prototype.weekInfo`.
*
* Pure day arithmetic on `date`'s ISO fields: no neighbouring year's week 1 is
* built as a date, because it can lie outside the representable range (week 1
* of -271821 starts before `-271821-04-19`, week 1 of +275761 after
* `+275760-09-13`) while `date` itself and its week-year are valid.
*
* Shared by `getLocaleWeekYear` (the year itself),
* `getWeeksInLocaleWeekYear` and `getWeeksInYear` (the week count, derived
* from the offsets).
*
* @example getLocaleWeekYearBounds(Temporal.PlainDate.from("2024-12-30"), 1, 4) // { weekYear: 2025, startOffsetDays: 0, endOffsetDays: 364 }
*/
export declare function getLocaleWeekYearBounds(date: Pick<Temporal.PlainDate, "year" | "dayOfYear" | "dayOfWeek">, firstDay: number, minimalDays: number): LocaleWeekYearBounds;