
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? bye, Tobias

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...
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

Hi, Jeff Garland wrote:
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");
Mmm... I even can't get this to compile.
date_test.cc:17: error: use of class template `template
Probably a better approach would be to check out the spirit grammer for rfc822 written by Peter Simons. Look for 'rfcdate' at
Thanks a millon! This looks interesting. Regards, Tobias

On Mon, 19 Sep 2005 01:50:37 +0200, Tobias Grimm wrote
Hi,
Jeff Garland wrote:
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");
Mmm... I even can't get this to compile.
Sorry I wasn't watching the boost versions -- this facet code is a 1.33 feature. It's pretty much impossible with 1.32 facet code...
Probably a better approach would be to check out the spirit grammer for rfc822 written by Peter Simons. Look for 'rfcdate' at
Thanks a millon! This looks interesting.
You'll still have to do some work to integrate them as rfcdate produces a tm and not a date-time type (although there is a simple function to convert a tm to a ptime). Oh and the posix_time_zone and local_time classes are also 1.33 features so if you want to use them you'll need to upgrade. But in lots of scenarios you can just drop the tz data and construct a UTC time...all depends on what you want to do after you get the time. Anyway, if you make a nice variant of the rfc822 parser and want to contribute it back I'll be happy to look at putting it in as at least an example ;-) Good luck. Jeff
participants (2)
-
Jeff Garland
-
Tobias Grimm