Skip to content

getWeeksInLocaleWeekYear

getWeeksInLocaleWeekYear(value: string, locale: string): number
import { getWeeksInLocaleWeekYear } from "@northguild/gmt/plain/calculate";

Return the number of weeks (52 or 53) in the locale week-numbering year

  • containing value, using locale’s first day of week and minimal-days-in-first-week.
  • getWeeksInYear’s locale-relative counterpart — that function uses the fixed ISO rule, this one uses locale’s week-numbering rule (via Intl.Locale.prototype.weekInfo), and the two can disagree on the same date.
  • Computed as the number of calendar days between the locale week-year’s start and the next week-year’s start, divided by 7 — always a whole number, since both bounds fall on the locale’s first day of week.
  • Returns null if value or locale is invalid.
Parameter Type Description
value string ISO PlainDate string
locale string BCP 47 locale tag (e.g. “en-US”, “fr-FR”)

52 or 53, or null on invalid input

getWeeksInLocaleWeekYear("2024-06-15", "en-US") // 52
getWeeksInLocaleWeekYear("2020-06-15", "de-DE") // 53
getWeeksInLocaleWeekYear("invalid", "en-US") // null

plain/calculate/getWeeksInLocaleWeekYear.ts