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

Re^4: RFC 822 date manipulation without DateTime module?

by GhodMode (Pilgrim)
on Jun 15, 2009 at 02:43 UTC ( [id://771519]=note: print w/replies, xml ) Need Help??


in reply to Re^3: RFC 822 date manipulation without DateTime module?
in thread RFC 822 date manipulation without DateTime module?

That is exactly what I was looking for. Unfortunately, it doesn't recognize all of the time zone specifiers.

Example:

use Time::Piece; my $pubdate = "Thu, 11 Jun 2009 11:50:00 PDT"; my $t = Time::Piece->strptime( "Thu, 11 Jun 2009 11:50:00 PDT", " +%a, %d %b %Y %H:%M:%S %Z" ); my $offset = $t->tzoffset; printf( "%s\n", $t ); printf( "%s\n", $t->tzoffset->seconds );
results in
ghodmode@home:perl ] ./timepiece.pl
garbage at end of string in strptime: PDT at /usr/lib/perl/5.10/Time/Piece.pm line 470.
Thu Jun 11 11:50:00 2009
0

I think I'm going to rely on the call to the shell's date for now. Later, if I want to make the program more portable, I'll probably just create a hash with a short list of time zone specifiers to convert them to the appropriate numeric offset. That would break if the program encountered a new zone, but it would work for my purposes.

Of course Date::Time is the right way to do it, but it's less portable because of the external dependency.

I like Time::Piece, though. I didn't know about this module and I anticipate using it a lot more in the future.

--
-- Ghodmode
Blessed is he who has found his work; let him ask no other blessedness.
-- Thomas Carlyle

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://771519]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (4)
As of 2024-03-30 00:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found