parseRFC822DateTime

The given array of char or random-access range of char or ubyte is expected to be in the format specified in RFC 5322 section 3.3 with the grammar rule date-time. It is the date-time format commonly used in internet messages such as e-mail and HTTP. The corresponding SysTime will be returned.

RFC 822 was the original spec (hence the function's name), whereas RFC 5322 is the current spec.

The day of the week is ignored beyond verifying that it's a valid day of the week, as the day of the week can be inferred from the date. It is not checked whether the given day of the week matches the actual day of the week of the given date (though it is technically invalid per the spec if the day of the week doesn't match the actual day of the week of the given date).

If the time zone is "-0000" (or considered to be equivalent to "-0000" by section 4.3 of the spec), a std.datetime.timezone.SimpleTimeZone with a utc offset of 0 is used rather than std.datetime.timezone.UTC, whereas "+0000" uses std.datetime.timezone.UTC.

Note that because SysTime does not currently support having a second value of 60 (as is sometimes done for leap seconds), if the date-time value does have a value of 60 for the seconds, it is treated as 59.

The one area in which this function violates RFC 5322 is that it accepts "\n" in folding whitespace in the place of "\r\n", because the HTTP spec requires it.

  1. SysTime parseRFC822DateTime(char[] value)
    @safe
    parseRFC822DateTime
    ()
    (
    scope const char[] value
    )
  2. SysTime parseRFC822DateTime(R value)

Throws

std.datetime.date.DateTimeException if the given string doesn't follow the grammar for a date-time field or if the resulting SysTime is invalid.

Examples

import core.time : hours;
import std.datetime.date : DateTime, DateTimeException;
import std.datetime.timezone : SimpleTimeZone, UTC;
import std.exception : assertThrown;

auto tz = new immutable SimpleTimeZone(hours(-8));
assert(parseRFC822DateTime("Sat, 6 Jan 1990 12:14:19 -0800") ==
       SysTime(DateTime(1990, 1, 6, 12, 14, 19), tz));

assert(parseRFC822DateTime("9 Jul 2002 13:11 +0000") ==
       SysTime(DateTime(2002, 7, 9, 13, 11, 0), UTC()));

auto badStr = "29 Feb 2001 12:17:16 +0200";
assertThrown!DateTimeException(parseRFC822DateTime(badStr));

Meta