getWeekOfMonth
Signature
Section titled “Signature”getWeekOfMonth(value: string, locale: string | string[]): number | nullReturn 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’sminDays, so a short leading week may not count as part of the month. - Comparison: date-fns’s
getWeekOfMonthreturns 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
valueorlocaleis invalid.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | string | ISO PlainDate string |
locale | string | 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 |
Returns
Section titled “Returns”1-based week-of-month row, or null on invalid input
Examples
Section titled “Examples”import { getWeekOfMonth } from "@northguild/gmt/plain/calculate";
getWeekOfMonth("2024-02-01", "en-US") // 1