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

http://perl5.git.perl.org/perl.git?a=search&h=HEAD&st=grep&s=strptime
corelist Time::Piece Time::Piece was first released with perl 5.009005
Perl does have that feature.

Replies are listed 'Best First'.
Re^4: RFC 822 date manipulation without DateTime module?
by GhodMode (Pilgrim) on Jun 15, 2009 at 02:43 UTC

    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