This seems to be a bug in Time::Piece->strptime(STRING, FORMAT) . Here is the code in question:
sub strptime { my $time = shift; my $string = shift; my $format = @_ ? shift(@_) : "%a, %d %b %Y %H:%M:%S %Z"; my @vals = _strptime($string, $format);
Start here. _strptime is the operating system's built-in strptime function . It seems to be returning local time, although this is not documented anywhere.
# warn(sprintf("got vals: %d-%d-%d %d:%d:%d\n", reverse(@vals))); return scalar $time->_mktime(\@vals, (ref($time) ? $time->[c_islocal] : 0));
Ok, so we use our _mktime method to convert the _strptime output to a Time::Piece object. The second parameter is whether _mktime should be interpreted as local time or UTC. When called as Time::Piece->strptime(STRING, FORMAT) , ref($time) will be false, and therefore _mktime will be called using $islocal=0 , i.e. _strptime returns the UTC time. This is wrong, and we found a mistake. (I don't know enough about C time functions to know how this should be done.)
}
So you should use localtime->strptime(STRING, FORMAT) . Also, this will still fail in older versions of the module due to another error in _mktime (my distribution comes with version 1.15, where it is still broken, but it is fixed in 1.20).
This is not even a strange problem related to %s . This happens with any call to Time::Piece->strptime :
$ perl -MTime::Piece -E'say $x=Time::Piece->strptime("11 Dec 2012 10:00","%d %b %Y %H:%M")->epoch;say scalar localtime $x' 1355220000 Tue Dec 11 04:00:00 2012 $ perl -MTime::Piece -E'say $x=localtime->strptime("11 Dec 2012 10:00","%d %b %Y %H:%M")->epoch;say scalar localtime $x' 1355220000 Tue Dec 11 04:00:00 2012 $ export PERL5LIB=Time-Piece-1.20/blib/lib:Time-Piece-1.20/blib/arch $ perl -MTime::Piece -E'say $x=Time::Piece->strptime("11 Dec 2012 10:00","%d %b %Y %H:%M")->epoch;say scalar localtime $x' 1355220000 Tue Dec 11 04:00:00 2012 $ perl -MTime::Piece -E'say $x=localtime->strptime("11 Dec 2012 10:00","%d %b %Y %H:%M")->epoch;say scalar localtime $x' 1355241600 Tue Dec 11 10:00:00 2012
nandhp
source share