parseRfc2822
Signature
Section titled “Signature”parseRfc2822(value: string): stringimport { parseRfc2822 } from "@northguild/gmt/zoned/parse";Parse an RFC 5322 (RFC 2822) date-time string — the fixed grammar email
Date:headers use — into a zoned ISO 8601 datetime string.- Decoding, not display. Accepts English weekday/month abbreviations only, per the fixed grammar (see
formatRfc2822’s JSDoc and roadmap Decision 1). - Accepts a leading day-of-week (not cross-validated against the computed date, the same deliberate scope limit
parseDateTimeWithPattern/J11 uses for itsEEEE/EEEtokens) and an optional:ssseconds field. - Accepts a 1- or 2-digit day (the formal grammar’s
1*2DIGIT), unlikeparseHttp/parseSql, which both require exactly 2 digits. - Accepts a numeric
+HHMM/-HHMMoffset or one of RFC 5322’s obsolete named zones (GMT,UT, and the eight North American zones); any other obs-zone letter is unrecognized and rejected. - The resulting offset becomes the zoned string’s time zone identifier (e.g.
-05:00), since RFC 2822 carries no IANA zone name to recover.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value |
string |
RFC 5322 date-time string (e.g. “Fri, 15 Mar 2024 14:30:00 -0400”) |
Returns
Section titled “Returns”zoned ISO 8601 datetime string, or “” on invalid input
Examples
Section titled “Examples”parseRfc2822("Fri, 15 Mar 2024 14:30:00 -0400") // "2024-03-15T14:30:00-04:00[-04:00]"parseRfc2822("5 Jan 2024 09:00:00 GMT") // "2024-01-05T09:00:00+00:00[+00:00]"parseRfc2822("not a date") // ""