Skip to content

parseHttp

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

Parse an RFC 7231 IMF-fixdate string — the fixed grammar HTTP headers like

  • Last-Modified/Date/Expires use — into a UTC ISO 8601 datetime string.
  • Decoding, not display. Accepts English weekday/month abbreviations only, per the fixed grammar (see formatHttp’s JSDoc and roadmap Decision 1).
  • IMF-fixdate only. RFC 7231 also lists two obsolete forms (rfc850-date, asctime-date) that real HTTP servers occasionally still emit; this is a documented limitation — neither is accepted here.
  • Day, hour, minute, and second must each be exactly 2 digits and the trailing zone must be the literal GMT — unlike parseRfc2822, no numeric offset or named-zone table is accepted.
  • The day-of-week is not cross-validated against the computed date, the same deliberate scope limit parseDateTimeWithPattern/J11 uses.
Parameter Type Description
value string RFC 7231 IMF-fixdate string (e.g. “Fri, 15 Mar 2024 14:30:00 GMT”)

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

parseHttp("Fri, 15 Mar 2024 14:30:00 GMT") // "2024-03-15T14:30:00Z"
parseHttp("Fri, 15 Mar 2024 14:30:00 -0400") // "" (not IMF-fixdate)
parseHttp("not a date") // ""

utc/parse/parseHttp.ts