Skip Menu |

This queue is for tickets about the Time-Piece CPAN distribution.

Report information
The Basics
Id: 121554
Status: resolved
Priority: 0/
Queue: Time-Piece

People
Owner: Nobody in particular
Requestors: DKOGAN [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: 1.31_02



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.
Subject: Re: [rt.cpan.org #121554] Time::Piece->strftime('%s') is erroneously affected by the 'TZ' environment
Date: Sun, 7 May 2017 17:59:12 -0500
To: bug-Time-Piece [...] rt.cpan.org
From: Samuel Smith <leon36 [...] gmail.com>
On 05/07/2017 04:34 PM, Dima Kogan via RT wrote: Show quoted text
> Sun May 07 17:34:01 2017: Request 121554 was acted upon. > Transaction: Ticket created by DKOGAN > Queue: Time-Piece > Subject: Time::Piece->strftime('%s') is erroneously affected by the 'TZ' > environment > Broken in: (no value) > Severity: (no value) > Owner: Nobody > Requestors: DKOGAN@cpan.org > Status: new > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=121554 > > > > 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. >
Hi, Thanks for the report. The current dev release (1.31_02) has fixed this issue. Expect the fix in the next stable release 1.32x. You can install 1.31_02 if you'd like, but I would not deploy it to a production/stable environment. Regards, Samuel Smith