Subject: | Time::Piece->strftime('%s') is erroneously affected by the 'TZ' environment |
Hi. I can use Time::Piece to interpret a seconds-since-the-epoch time, and then convert it back. I would expect to get the same thing on the output, as I get on the input, so the following should print '1500000000', but instead it prints '1500028800':
use Time::Piece;
my $t = 1500000000;
my $tp = Time::Piece->strptime( $t, '%s' );
print $tp->strftime( '%s' );
In both strptime() and strftime() '%s' should be seconds since the epoch UTC, so the timezone shouldn't be relevant, but here it IS relevant by mistake. The following modification to the test snippet above makes it work:
use Time::Piece;
my $t = 1500000000;
my $tp = Time::Piece->strptime( $t, '%s' );
$ENV{TZ} = 'UTC';
print $tp->strftime( '%s' );
Thanks! I'm using Time::Piece from the libperl5.24 package version 5.24.1~rc4-1 on Debian.