Skip to content

isValidRfc2822DateTime

isValidRfc2822DateTime(value: string): boolean

Return 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 parseRfc2822 returns 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 rfc2822DateTime pattern 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). parseRfc2822 lists each form.
  • Checks the calendar as well as the shape. The pattern matches a day that does not exist: 31 Feb, 29 Feb 2023 and 31 Jun are 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 with formatRfc2822.
ParameterTypeDescription
valuestringcandidate RFC 5322 date-time string

boolean indicating validity

import { isValidRfc2822DateTime } from "@northguild/gmt/zoned/validate";
isValidRfc2822DateTime("Fri, 15 Mar 2024 14:30:00 -0400") // true
output 

zoned/validate/isValidRfc2822DateTime.ts