convertZonedToCalendar
Signature
Section titled “Signature”convertZonedToCalendar(value: string, calendar: CalendarSystem): stringExpress a zoned datetime in a calendar system: the RFC 9557 string Temporal.ZonedDateTime#toString() writes for that instant, zone and calendar.
- The instant, the wall time, the UTC offset, the IANA zone and the digits are all unchanged: the date is always written as ISO 8601. A
[u-ca=<id>]annotation after the[timeZone]annotation names the calendar (RFC 9557 §3.3, §4.1). Eras and calendar years are never part of the string. "iso8601"writes a bare ISO zoned string; every other calendar,"gregory"included, is annotated.- Accepts a bare ISO zoned datetime or any calendar-annotated one GMT reads (see
isValidCalendarZonedDateTime), so conversions chain between calendars. calendaris a canonical calendar id; like Temporal’swithCalendar, an alias or another letter case is canonicalized.- Returns "" on invalid input or an unsupported
calendar. Compatibility: since 1.16.0 the string is RFC 9557. Earlier releases wrote the calendar’s own year, month and day, a;era=suffix forjapaneseandethiopic, the calendar annotation before the time zone, and the idsgregorian,taiwan,islamic-tabularandethiopic-amete-alem; those strings are not converted.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | string | ISO zoned datetime string, optionally calendar-annotated |
calendar | CalendarSystem | target calendar id (“iso8601” | “gregory” | “hebrew” | “islamic-civil” | “islamic-tbla” | “islamic-umalqura” | “japanese” | “buddhist” | “roc” | “persian” | “indian” | “ethiopic” | “ethioaa” | “coptic”) |
Returns
Section titled “Returns”RFC 9557 zoned datetime string, or "" on invalid input
Related types
Section titled “Related types”Examples
Section titled “Examples”import { convertZonedToCalendar } from "@northguild/gmt/zoned/convert";
convertZonedToCalendar("2024-10-03T14:30:45-04:00[America/New_York]", "hebrew") // "2024-10-03T14:30:45-04:00[America/New_York][u-ca=hebrew]"