|
Boost Users : |
From: Jeff Garland (jeff_at_[hidden])
Date: 2005-09-18 10:24:38
On Sun, 18 Sep 2005 03:16:29 +0200, Tobias Grimm wrote
> Hi!
>
> I'm trying to parse a rfc822 date as used in RSS feeds. It looks
> like this:
>
> Sat, 07 Sep 2002 00:00:01 GMT
>
> Is this possible with time_facet somehow? I think at least the time zone
> can't be parsed, because the corresponding format specifiers are for
> output only. Any idea how this kind of date format should be parsed?
You are exactly right. For the base time information you should be able to do
the following (I didn't test this)...
time_facet* timefacet = new time_facet("%a, %d %b %Y %H:%M:%S");
std::stringstream ss;
ss.str("Sat, 07 Sep 2002 00:00:01 GMT");
ss.imbue(std::locale(std::locale::classic(), timefacet));
ptime t;
ss >> t;
As for the timezone RFC 822 makes some unfortunate 'special cases' for US
based timezones. Life would be better if they would conform to posix 1003.1
specifications. So basically you will need a little parsing engine to extract
the timezone and do something useful with it. I'd recommend mapping the
special cases (eg: MDT, ECT) to a posix time string which you can use to
create a posix_time_zone. You can find details at:
http://www.boost.org/doc/html/date_time/local_time.html#date_time.local_time.posix_time_zone
>From there you can construct the appropriate local_time instance.
Probably a better approach would be to check out the spirit grammer for rfc822
written by Peter Simons. Look for 'rfcdate' at
http://spirit.sourceforge.net/repository/applications/show_contents.php
This could be easily combined with date-time to do what you want.
Jeff
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net