The given array of
char or random-access range of
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).
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.
.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));