Skip to content

convertZonedToCalendar

convertZonedToCalendar(value: string, calendar: CalendarSystem): string

Express 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.
  • calendar is a canonical calendar id; like Temporal’s withCalendar, 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 for japanese and ethiopic, the calendar annotation before the time zone, and the ids gregorian, taiwan, islamic-tabular and ethiopic-amete-alem; those strings are not converted.
ParameterTypeDescription
valuestringISO zoned datetime string, optionally calendar-annotated
calendarCalendarSystemtarget calendar id (“iso8601” | “gregory” | “hebrew” | “islamic-civil” | “islamic-tbla” | “islamic-umalqura” | “japanese” | “buddhist” | “roc” | “persian” | “indian” | “ethiopic” | “ethioaa” | “coptic”)

RFC 9557 zoned datetime string, or "" on invalid input

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]"
output 

zoned/convert/convertZonedToCalendar.ts