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.

40 lines • 2.2 kB
/** * Return the ISO 8601 week date — week-numbering year, week and weekday — for `value`. * * Vessel schedules, production plans and retail reports are published by week number, and a * week number alone is ambiguous: the week-numbering year is not the calendar year at either * end of a year, so all three fields come back together rather than as three calls a caller * could combine inconsistently. * * - A week-numbering year has 53 weeks roughly every five to six years, and 52 otherwise. * - `value` must be zoneless — an ISO date or datetime, as `isValidIsoDateLike` accepts. An * offset, a `Z` or a bracketed zone makes it a moment rather than a calendar date; convert * it in the zone you mean first (`convertUtcToZoned` then `convertZonedToPlainDateTime`), * or floor it with `floorToZone`. * - Returns null on invalid input. * * @param value zoneless ISO 8601 date or datetime string (e.g. "2024-06-15") * @returns { year, week, weekday }, or null on invalid input * * @example getIsoWeekDate("2024-06-15") // { year: 2024, week: 24, weekday: 6 } * @example getIsoWeekDate("2027-01-01") // { year: 2026, week: 53, weekday: 5 } (week-year 2026, not 2027) * @example getIsoWeekDate("2024-12-30") // { year: 2025, week: 1, weekday: 1 } (a December date in the next week-year) * @example getIsoWeekDate("2020-12-31") // { year: 2020, week: 53, weekday: 4 } (a 53-week ISO year) * @example getIsoWeekDate("2024-06-15T23:59:59") // { year: 2024, week: 24, weekday: 6 } * @example getIsoWeekDate("2024-06-15T12:00:00Z") // null (a moment, not a calendar date) * @example getIsoWeekDate("invalid") // null */ export declare function getIsoWeekDate(value: string): { /** * The ISO 8601 week-numbering year: the calendar year that holds the Thursday of the date's week. * It differs from the date's own calendar year for some dates in late December and early January. */ year: number; /** * The ISO 8601 week number, 1 through 53. Week 1 is the week that holds the year's first * Thursday, and weeks start on Monday. */ week: number; /** The ISO 8601 day of the week, 1 (Monday) through 7 (Sunday). */ weekday: number; } | null;