isValidRfc2822DateTime
Signature
Section titled “Signature”isValidRfc2822DateTime(value: string): booleanReturn true when value is a real RFC 5322 (RFC 2822) date-time: the date an email Date: header carries, such as Fri, 15 Mar 2024 14:30:00 -0400.
- True exactly when
parseRfc2822returns a zoned string for the same value: the validator calls the parser, so the two cannot disagree. - Reads what a conformant receiver must, which is more than the strict
rfc2822DateTimepattern matches: RFC 5322 §3.3 folding white space, comments, names in any case and a year of more than four digits, and the §4 obsolete syntax (2- and 3-digit years, military and other alphabetic zones).parseRfc2822lists each form. - Checks the calendar as well as the shape. The pattern matches a day that does not exist:
31 Feb,29 Feb 2023and31 Junare false here. - The day-of-week must match the date. RFC 5322 §3.3: “the day-of-week (if included) MUST be the day implied by the date”. The pattern does not check it.
- False for an hour above 23, a minute above 59, zone minutes above 59 and an offset of 24 hours or more, all of which the pattern matches. False for a second of 60: GMT rejects leap seconds.
- False for a non-string. Read the value with
parseRfc2822; write one withformatRfc2822.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | string | candidate RFC 5322 date-time string |
Returns
Section titled “Returns”boolean indicating validity
Examples
Section titled “Examples”import { isValidRfc2822DateTime } from "@northguild/gmt/zoned/validate";
isValidRfc2822DateTime("Fri, 15 Mar 2024 14:30:00 -0400") // true