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.

34 lines • 1.93 kB
/** * Return the week of the year for a given ISO 8601 zoned datetime string. * * - `"monday"` is the ISO 8601 week of the week-year: week 1 is the week containing the * first Thursday, so late-December days can be week 1 of the next year (a value on 2024-12-31 * → 1). The result is 1–53. * - `"sunday"` is the UTS #35 week of the week-year with a Sunday first day and minimal days 1: * week 1 is the Sunday-first week holding 1 January, so late-December days can be week 1 of the * next year (2024-12-31 → 1, 2000-12-30 → 53). The result is 1–53. * - The week is read from the value's own date on its own wall clock. * - Returns null for invalid input. * * @param value ISO zoned datetime string * @param optionsArg optional setting for the week's first day * @returns Week number (1-53), or null on invalid input * * @example parseWeekFromZoned("2024-01-01T14:30:45.123+00:00[UTC]") // 1 * @example parseWeekFromZoned("2024-01-08T14:30:45.123+00:00[UTC]") // 2 * @example parseWeekFromZoned("2024-12-31T12:00:00+00:00[UTC]") // 1 (ISO week 1 of 2025) * @example parseWeekFromZoned("2024-12-31T12:00:00+00:00[UTC]", { weekStartsOn: "sunday" }) // 1 (its Sunday-first week holds 1 January 2025) * @example parseWeekFromZoned("2000-12-31T12:00:00+00:00[UTC]", { weekStartsOn: "sunday" }) // 1 (its Sunday-first week holds 1 January 2001) * @example parseWeekFromZoned("invalid") // null */ export declare function parseWeekFromZoned(value: string, optionsArg?: { /** * The first day of the week, which sets how the week is numbered. `"monday"` gives the ISO 8601 * week number, where week 1 holds the year's first Thursday; `"sunday"` gives the UTS #35 week * number with a Sunday first day and one minimal day, where week 1 holds 1 January. Any other * value returns `null`. * * @defaultValue `"monday"` */ weekStartsOn?: "monday" | "sunday"; }): number | null;