Skip to content

parseYearMonth

parseYearMonth(value: string): string

Return the canonical YYYY-MM form of an ISO year-month string (±YYYYYY-MM outside 0000-9999).

  • Reads YYYY-MM and ±YYYYYY-MM; writes the shortest form. The reference day is never written.
  • The extended form only: 202610 is refused, as isValidDate refuses 20241225.
  • A date such as 2026-10-01 is not a year-month: use parseYearMonthFromDate.
  • The range is Temporal’s: -271821-04 to +275760-09.
  • Annotations are read as isValidYearMonth reads them: elective and time zone annotations are ignored, an unknown critical one refuses, and u-ca must be iso8601 in any case.
  • Returns "" for invalid input.
ParameterTypeDescription
valuestringISO year-month string

the YYYY-MM string, or "" on invalid input

import { parseYearMonth } from "@northguild/gmt/plain/parse";
parseYearMonth("2026-10") // "2026-10"
output 

plain/parse/parseYearMonth.ts

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.