parseYearMonthWithPattern
Signature
Section titled “Signature”parseYearMonthWithPattern(value: string, pattern: string, locale?: string | string[], options?: TwoDigitYearOptions): stringParse a year-month string against a caller-supplied token pattern (e.g. "MM/yyyy", "MMMM yyyy") and return it as an ISO year-month string, YYYY-MM.
-
Decoding, not display. This reads a known, fixed producer format. A pattern with a day, weekday or time token returns
""— useparseDateWithPatternfor a full date. -
The pattern needs both a year and a month, otherwise
"". -
Digits are ASCII, as in the other pattern parsers. ### Token table
Token Field Width Range Notes yyyyyear 4 digits 0000–9999 yyyear 2 digits — Read through options.yearWindow; with no window the result is""MMmonth 2 digits 01–12 Mmonth 1-2 digits 1–12 MMMMmonth name (long) locale — Reads the format-context name (“октября”) or the stand-alone name (“октябрь”); UTS #35 Part 4, Parsing Dates and Times MMMmonth name (short) locale — Reads either context, as MMMMLLmonth 2 digits 01–12 Stand-alone context; read as MMLmonth 1-2 digits 1–12 Stand-alone context; read as MLLLLmonth name (long) locale — Same names as MMMMLLLmonth name (short) locale — Same names as MMMGG/GGGGera locale — Qualifies the year: 1 BC is year 0000 -
Literal text follows UTS #35: text in
'single quotes'is a literal,''is one literal quote, and a quote that never closes makes the pattern malformed (""). -
Month names match case-insensitively. A
-u-ca-locale extension is overridden to Gregorian. -
Name tokens are locale-aware. If
localeis omitted (or an empty list) and the pattern uses one, GMT reads English names in"en". An ill-formed tag returns"".
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | string | The string to decode (e.g. “10/2026”) |
pattern | string | The token pattern describing value’s shape (e.g. “MM/yyyy”) |
locale | string | string[] | Optional BCP 47 locale tag, or a preference list of tags, for name-based tokens (default “en”) |
Options
Section titled “Options”options
The hundred-year window a yy token resolves in
Type: TwoDigitYearOptions.
| Option | Type | Default | Description |
|---|---|---|---|
yearWindow? | number | "rolling" | None. A value with a two-digit year returns the sentinel: no standard says which century it belongs to, so the caller states it. | The hundred-year window a two-digit year falls in. A number is the first year of a fixed window, an integer from 0 to 9900: 2000 reads 00–99 as 2000–2099; 1950 reads 50–99 as 1950–1999 and 00–49 as 2000–2049. A fixed window gives the same answer in any year, so it is the form for stored data, archives and anything re-processed later. "rolling" is the hundred years around today: from 50 years before the current UTC calendar year to 49 years after it (in 2026, 1976–2075). It is the form for live messages and never needs maintenance, but it gives a different answer for the same stored value as years pass. Any other value returns the function’s sentinel. |
Returns
Section titled “Returns”the YYYY-MM string, or "" on no match, malformed pattern, or invalid input
Related types
Section titled “Related types”Examples
Section titled “Examples”import { parseYearMonthWithPattern } from "@northguild/gmt/plain/parse";
parseYearMonthWithPattern("10/2026", "MM/yyyy") // "2026-10"Source
Section titled “Source”Code examples: MIT-0. Packages: MIT. Third-party data and components: their own licences, credited where they appear. Everything else:© 2026 NorthGuild, all rights reserved.