This functionality is needed quite often but doesn't seem to be present in phobos.
The date fields in HTTP headers are encoded as date-time according to
http://www.ietf.org/rfc/rfc822.txt.
example: Tue, 10 Jun 2014 01:00:34 GMT
specs:
5. DATE AND TIME SPECIFICATION
5.1. SYNTAX
date-time = [ day "," ] date time ; dd mm yy
; hh:mm:ss zzz
day = "Mon" / "Tue" / "Wed" / "Thu"
/ "Fri" / "Sat" / "Sun"
date = 1*2DIGIT month 2DIGIT ; day month year
; e.g. 20 Jun 82
month = "Jan" / "Feb" / "Mar" / "Apr"
/ "May" / "Jun" / "Jul" / "Aug"
/ "Sep" / "Oct" / "Nov" / "Dec"
time = hour zone ; ANSI and Military
hour = 2DIGIT ":" 2DIGIT [":" 2DIGIT]
; 00:00:00 - 23:59:59
zone = "UT" / "GMT" ; Universal Time
; North American : UT
/ "EST" / "EDT" ; Eastern: - 5/ - 4
/ "CST" / "CDT" ; Central: - 6/ - 5
/ "MST" / "MDT" ; Mountain: - 7/ - 6
/ "PST" / "PDT" ; Pacific: - 8/ - 7
/ 1ALPHA ; Military: Z = UT;
; A:-1; (J not used)
; M:-12; N:+1; Y:+12
/ ( ("+" / "-") 4DIGIT ) ; Local differential
; hours+min. (HHMM)
Comment #1 by issues.dlang — 2014-06-10T02:18:36Z
Hmmm. I don't know. Sure, the RFC 5322 date format is used in a number of internet-related specs, but the way it's parsed is rather specific to those specs. I'm not convinced that Phobos is the right place for it.
I do have an implementation of this that's in a library that I've been working on (which implements RFC 5322) that I intend to post within the next couple of months (how soon will depend on how much time I have to work on it), but I am inclined to think that a 3rd party library like that is a better place for it, particularly given the insane amount of muck involved with parsing that format correctly - muck which is specific to RFC 5322 and its related specs. And I certainly wouldn't want to encourage the use of the RFC 5322 format outside of the specs that require it, since it's really a horrible format (much as it's slightly better than what was in the obsoleted RFC 822 - part of the problem being that you still have to parse the really bad stuff from RFC 822 even though it's illegal to create many such strings now with RFC 5322).
Well, I can certainly do it, though I wouldn't make it as flexible as what I'm doing for the library that I'm working on. Supporting CFWS (comment folding whitespace) will certainly make it worse, but that would be hidden from the API. It just makes for some ugly code.
Would supporting random-access ranges of char and ubyte (as well as string) be sufficient? Adding more than that pretty much means duplicating all of the code, which I don't like (much as I'm going to do it in my library for flexibility's sake), and given where these dates are _supposed_ to be used, it doesn't necessarily make sense to support wchar[] or dchar[]. Or I could just make it operate on ranges of dchar and not care much about efficiency, though I'm not a fan of that idea. What I've been working on is specifically written with the idea that you're operating on ranges of char or ubyte, because that's what IMF (rfc 5322) messages always are.
Comment #5 by github-bugzilla — 2014-06-18T20:08:35Z
Commits pushed to master at https://github.com/D-Programming-Language/phoboshttps://github.com/D-Programming-Language/phobos/commit/daab9927fa0e7c224e1b2200c2c287957580aa03
Implement issue# 12886: function for parsing RFC822/5322 date-time format.
The RFC 822 / 5322 date-time format should be taken out and shot, but
unfortunately, it _is_ used in e-mail, HTTP, RTSP, etc. Most code which
deals with it is probably going to need to handle the rest of whatever
spec it's interacting with rather than just the date-time format, but
there are cases where this would be useful on its own (e.g. Martin
apparently needs something like this in the dmd installer), so I'm
adding a function to parse this format and return a SysTime to
std.datetime.
However, that's all I'm adding. I find it very hard to believe that
anyone who needs to produce this particular format doesn't need a lot of
other functionality specific to whatever spec they're dealing with, and
the function for generating the date-time format presumably will be
included with that (and I definitely don't want to encourage this
format's use anyway, since it's a horrible format). So, I'm just adding
a function for parsing the format, not generating it.
parseRFC822DateTime _should_ fully and correctly implement the format as
outlined in RFC 5322 (including the obsolete syntax from RFC 822 that no
one is supposed to be generating anymore and the comment folding
whitespace nonsense that should never have been legal anywhere but at
the end). And the tests are quite thorough, so it's unlikely that I
missed anything, but you never know.
https://github.com/D-Programming-Language/phobos/commit/e63514cea498c1b97a36cec3c93058fbc18eac17
Merge pull request #2253 from jmdavis/rfc822
Implement issue# 12886: function for parsing RFC822/5322 date-time format.