Skip to content

isValidYearMonth

isValidYearMonth(value: string): boolean
isValidYearMonth(value: void | {} | null | undefined): boolean
isValidYearMonth(value: unknown): value is string

Return true if value is a valid ISO year-month string: YYYY-MM or ±YYYYYY-MM.

  • The part before the first annotation must match plainYearMonth: the extended form only (202610 is refused, as isValidDate refuses 20241225), a four-digit year or a sign and six digits, never -000000.
  • The range is Temporal’s: -271821-04 to +275760-09.
  • A date such as 2026-10-01 is not a year-month: use parseYearMonthFromDate.
  • Reads RFC 9557 annotations as Temporal.PlainYearMonth.from does: elective ones ([foo=bar]) and a time zone annotation are ignored, and an unknown critical one ([!foo=bar]) is rejected.
  • The calendar must be iso8601, in any case ([u-ca=ISO8601] is accepted); any other calendar is refused.
  • Rejects a time, a Z and an offset.
  • A value that is not a string, a String object included, returns false. A true result narrows an unknown value to string.
ParameterTypeDescription
valuestringany value; a string is checked as an ISO year-month

boolean indicating validity

import { isValidYearMonth } from "@northguild/gmt/plain/validate";
isValidYearMonth("2026-10") // true
output 

plain/validate/isValidYearMonth.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.