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

Report information
The Basics
Id:
127864
Status:
open
Priority:
Low/Low
Queue:

People
Owner:
Nobody in particular
Requestors:
karthik.hiraskar [...] oracle.com
Cc:
AdminCc:

BugTracker
Severity:
(no value)
Broken in:
(no value)
Fixed in:
(no value)



Subject: Bug in Time::Piece strftime for year older than 1970
Date: Fri, 30 Nov 2018 05:46:41 -0800 (PST)
To: bug-Time-Piece@rt.cpan.org
From: Karthik Hiraskar <karthik.hiraskar@oracle.com>

Hi,

Time::Piece, strftime not giving valid output for any year before 1970.

And it seems this issue is only on windows, please let me know if any fix available or planning to fix in future.

 

Here is code samples which is not producing right output:

use Time::Piece;

my $test_date = Time::Piece->strptime( "1969-01-01", "%Y-%m-%d %H:%M:%S");

print $test_date->strftime("%b %d %Y, %A [%H:%M:%S]");

 

 

All dates on or after 1970-01-01 is producing right output, but older are simply not producing any output in response.

 

 

Thanks & Regards,

KK

 

RT-Send-CC: karthik.hiraskar@oracle.com
On Fri Nov 30 09:20:27 2018, karthik.hiraskar@oracle.com wrote:
Show quoted text
> Hi, > > Time::Piece, strftime not giving valid output for any year before > 1970. > > And it seems this issue is only on windows, please let me know if any > fix available or planning to fix in future. > > > > Here is code samples which is not producing right output: > > use Time::Piece; > > my $test_date = Time::Piece->strptime( "1969-01-01", "%Y-%m-%d > %H:%M:%S"); > > print $test_date->strftime("%b %d %Y, %A [%H:%M:%S]"); > > > > > > All dates on or after 1970-01-01 is producing right output, but older > are simply not producing any output in response. > > > > > > Thanks & Regards, > > KK > >
I think the problem is the implementation of strftime was changed in version 1.30. Strftime now returns the data based upon the epoch which is stored inside the current Time::Piece instance. So clearly for dates prior to 1970 this can be undefined behavior (since the epoch would be negative). This was mainly done to get around issues with daylight savings time errors when using strftime so it probably will be left as is. The good news is, Time::Piece has many methods to display its current time data. $t->strftime("%b %d %Y, %A [%H:%M:%S]") could be rewritten as: sprintf "%s %s %s, %s [%s]", $t->monname, $t->mday, $t->year, $t->day, $t->hms There is also a raw interface to strftime provided by the POSIX module: See https://metacpan.org/pod/distribution/perl/ext/POSIX/lib/POSIX.pod#strftime You just need to pass the individual date parts to it. I know, less than ideal, but I assume this will work for your situation?


This service runs on Request Tracker, is sponsored by The Perl Foundation, and maintained by Best Practical Solutions.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.