View source code
Display the source code in std/datetime/systime.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone.

Function std.datetime.systime.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.

SysTime parseRFC822DateTime (
  scope const char[] value
) @safe;

SysTime parseRFC822DateTime(R) (
  scope R value
if (isRandomAccessRange!R && hasSlicing!R && hasLength!R && (is(immutable(ElementType!R) == immutable(char)) || is(immutable(ElementType!R) == immutable(ubyte))));

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 SimpleTimeZone with a utc offset of 0 is used rather than UTC, whereas "+0000" uses 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.


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


import core.time : hours;
import : 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";


Jonathan M Davis


Boost License 1.0.