Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

How to Parse an RFC 822 style date with Time::Piece?

by jaldhar (Vicar)
on Feb 19, 2003 at 19:43 UTC ( #236782=perlquestion: print w/ replies, xml ) Need Help??
jaldhar has asked for the wisdom of the Perl Monks concerning the following question:

I'm using the excellent Time::Piece module and it is working well for me except for one thing. I need to parse an RFC 822 style Date with strptime. What I want is something like:

$date = Time::Piece->strptime($msg->date, "%a, %d %b %Y %H:%M:%S %z");
but apparently %z is a GNUism and not supported by the module. So is there an alternate format string I can use instead? Or if worst comes to worst, is there another module that can convert an RFC 822 date into a comparable quantity?

--
જલધર

Comment on How to Parse an RFC 822 style date with Time::Piece?
Download Code
Re: How to Parse an RFC 822 style date with Time::Piece?
by Aristotle (Chancellor) on Feb 19, 2003 at 21:29 UTC
    In the simplest case, you can use HTTP::Date. If it can parse such dates (I think so, but not sure off the top of my head), a really comprehensive solution written to offer speed and versatility would be Date::Calc - it's become my favourite date/time module.

    Makeshifts last the longest.

Re: How to Parse an RFC 822 style date with Time::Piece?
by steves (Curate) on Feb 19, 2003 at 21:53 UTC

    Date::Manip should parse this. It's slower than most (all Perl) but I found that it parses almost anything you can throw at it.

      Even its author says (in the POD even, IIRC) that you should probably try to make something else work before you go for Date::Manip though. It's a great module when you are trying to cope with sloppy date/time descriptions or want to allow them, but it tries to be so smart it really shouldn't be used if you don't really need its capabilities.

      Makeshifts last the longest.

        I've seen that comment in the Date::Manip docs. But it's so easy to use and just gets the job done. If I'm concerned with performance, I'll have to look into some of the many other date and time modules. But I have lots of stuff (for example cron jobs) where I'll gladly trade some CPU cycles to save a few of my cycles.

Re: How to Parse an RFC 822 style date with Time::Piece?
by jaldhar (Vicar) on Feb 24, 2003 at 05:35 UTC

    Thanks to all those who replied. Sorry for not getting back to you but I didn't get a chance to work on this problem again until today. I uploaded the script here so you can see what I was doing. I'd appreciate any suggestions for speeding it up. For parsing the dates, I took aristotle's suggestion and used HTTP:Date. It was perfect for my needs.

    --
    જલધર

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://236782]
Approved by Kanji
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2014-12-21 20:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (107 votes), past polls