isValidCalendarDate
Signature
Section titled “Signature”isValidCalendarDate(value: string): booleanReturn true if value is a valid GMT PlainDate string: a bare ISO date (“2024-10-03”) or an RFC 9557 calendar-annotated date (“2024-10-03[u-ca=hebrew]”), as Temporal.PlainDate#toString() and convertDateToCalendar write it.
- The digits are the ISO date whatever the calendar, so the ISO date must be valid and within Temporal’s range (-271821-04-19 to +275760-09-13). The year is four digits or a sign and six.
- A
[u-ca=<id>]annotation, optionally critical ([!u-ca=hebrew]). Temporal’sCanonicalizeCalendarvalidates the id, folding case and aliases ([u-ca=HEBREW],[u-ca=ethiopic-amete-alem]), and the calendar must be one GMT supports (CalendarSystem);chinese,dangi,islamicandislamic-rgsareturn false. - The annotations follow Temporal’s ISO grammar, as
Temporal.PlainDate.fromreads them: a time zone annotation and elective unknown annotations ([foo=bar]) are ignored and the firstu-caannotation names the calendar; an unknown critical annotation ([!foo=bar]) or a secondu-caannotation when either is critical returns false. - A date-time is valid and names its date, as
Temporal.PlainDate.fromreads it ("2024-10-03T14:30[u-ca=hebrew]"is 2024-10-03 in Hebrew): the time is dropped. - The part before the first
[must match GMT’s strict extended shape, asisValidDateandisValidDateTimerequire: basic format (20241003), a space or lower-casetseparator, a UTC offset or designator and a leap second (second60) return false, althoughTemporal.PlainDate.fromreads all but the designator. - Returns false for non-strings or empty strings. Compatibility: since 1.16.0 the string is RFC 9557, and a date-time is read as its date (earlier releases returned false). Earlier releases accepted calendar-native digits,
;era=and the idsgregorian,taiwan,islamic-tabularandethiopic-amete-alem; a;era=string or a six-digit unsigned year now returns false, and any other such string is read as the ISO date its digits spell.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | string | ISO PlainDate string, optionally calendar-annotated |
Returns
Section titled “Returns”boolean indicating validity
Examples
Section titled “Examples”import { isValidCalendarDate } from "@northguild/gmt/plain/validate";
isValidCalendarDate("2024-10-03") // true