Skip to content

parseRfc3339

parseRfc3339(value: string): string
import { parseRfc3339 } from "@northguild/gmt/zoned/parse";

Parse a strict RFC 3339 datetime string into a zoned ISO 8601 datetime

  • string.
  • Accepts T, t, or a single space as the date/time separator (all three are valid RFC 3339, unlike GMT’s own zoned strings which always use T) and either Z/z or a numeric ±HH:MM offset.
  • RFC 3339 carries no IANA zone name, so the parsed offset becomes the result’s time zone identifier too (e.g. Z+00:00[+00:00]) — the same fixed-offset-as-zone convention parseRfc2822 uses.
  • Rejects GMT’s own bracketed zoned strings (...+00:00[UTC]) — that annotation is not valid RFC 3339 input; use Temporal.ZonedDateTime.from / isValidZonedDateTime directly for GMT’s native format instead.
Parameter Type Description
value string RFC 3339 datetime string (e.g. “2024-03-15T14:30:00-04:00”)

zoned ISO 8601 datetime string, or “” on invalid input

parseRfc3339("2024-03-15T14:30:00-04:00") // "2024-03-15T14:30:00-04:00[-04:00]"
parseRfc3339("2024-03-15T14:30:00Z") // "2024-03-15T14:30:00+00:00[+00:00]"
parseRfc3339("2024-03-15T14:30:00+00:00[UTC]") // "" (bracket annotation not valid RFC 3339)
parseRfc3339("not a date") // ""

zoned/parse/parseRfc3339.ts