Skip to content

getWeekOfMonth

getWeekOfMonth(value: string, locale: string | string[]): number | null

Return the 1-based row value falls on within its month’s calendar grid, using locale’s first day of week.

  • Week 1 is the row containing the 1st of the month, even when that row is a partial week. This is GMT’s own rule, not a standard’s: a month grid draws every day of the month, so its first row always holds the 1st.
  • Not CLDR’s week-of-month field (W, UTS #35): that count applies the locale’s minDays, so a short leading week may not count as part of the month.
  • Comparison: date-fns’s getWeekOfMonth returns the same number for the same first day of week.
  • Distinct from ISO weekOfYear: this counts rows within a single month’s grid, reset every month, rather than weeks since Jan 1.
  • Resolves the locale’s first day of week via Intl.Locale.prototype.weekInfo.
  • Returns null if value or locale is invalid.
ParameterTypeDescription
valuestringISO PlainDate string
localestring | string[]BCP 47 locale tag (e.g. “en-US”, “fr-FR”), or a preference list of tags (ECMA-402; the first with locale data is read). Required: omitted, or an empty list (which ECMA-402 would resolve to the host default), returns null

1-based week-of-month row, or null on invalid input

import { getWeekOfMonth } from "@northguild/gmt/plain/calculate";
getWeekOfMonth("2024-02-01", "en-US") // 1
output 

plain/calculate/getWeekOfMonth.ts