Skip Menu |
 

This queue is for tickets about the Test-MockTime CPAN distribution.

Report information
The Basics
Id: 124508
Status: resolved
Priority: 0/
Queue: Test-MockTime

People
Owner: Nobody in particular
Requestors: bitcardbmw [...] lsmod.de
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.15
Fixed in: 0.16



Subject: test fails in 2020
Download (untitled) / with headers
text/plain 1.2k
tests failed after 2020-01-01 because of an ambiguity of two-digit years. man Time::Local says Years in the range 0..99 are interpreted as shorthand for years in the rolling "current century," defined as 50 years on either side of the current year. Thus, today, in 1999, 0 would refer to 2000, and 45 to 2045, but 55 would refer to 1955. Twenty years from now, 55 would instead refer to 2055. This is messy, but matches the way people currently think about two digit dates. Whenever possible, use an absolute four digit year instead. This patch fixed it for me: Index: Test-MockTime-0.15/t/test.t =================================================================== --- Test-MockTime-0.15.orig/t/test.t +++ Test-MockTime-0.15/t/test.t @@ -38,7 +38,9 @@ ok(($mock >= 100) && ($mock <= 101), "Ab sleep 2; $mock = time; ok(($mock >= 102) && ($mock <= 103), "Absolute time is still in sync after two seconds sleep:$mock"); -$mock = Time::Local::timelocal(localtime); +my @localtime = localtime; +$localtime[5] += 1900; # to make sure that year=70 is not interpreted as 2070 +$mock = Time::Local::timelocal(@localtime); $real = Time::Local::timelocal(CORE::localtime); ok($mock <= $real, "localtime seems ok"); Test::MockTime::set_fixed_time(CORE::time);
Download (untitled) / with headers
text/plain 1.4k
On Wed Feb 21 21:57:01 2018, bmwiedemann wrote: Show quoted text
> tests failed after 2020-01-01 > because of an ambiguity of two-digit years. > > man Time::Local says > Years in the range 0..99 are interpreted as shorthand for years in > the rolling "current century," defined as 50 years on either side > of the current year. Thus, today, in 1999, 0 would refer to 2000, > and 45 to 2045, but 55 would refer to 1955. Twenty years from now, > 55 would instead refer to 2055. This is messy, but matches the way > people currently think about two digit dates. Whenever possible, > use an absolute four digit year instead. > > > This patch fixed it for me: > > Index: Test-MockTime-0.15/t/test.t > =================================================================== > --- Test-MockTime-0.15.orig/t/test.t > +++ Test-MockTime-0.15/t/test.t > @@ -38,7 +38,9 @@ ok(($mock >= 100) && ($mock <= 101), "Ab > sleep 2; > $mock = time; > ok(($mock >= 102) && ($mock <= 103), "Absolute time is still in sync > after two seconds sleep:$mock"); > -$mock = Time::Local::timelocal(localtime); > +my @localtime = localtime; > +$localtime[5] += 1900; # to make sure that year=70 is not interpreted > as 2070 > +$mock = Time::Local::timelocal(@localtime); > $real = Time::Local::timelocal(CORE::localtime); > ok($mock <= $real, "localtime seems ok"); > Test::MockTime::set_fixed_time(CORE::time);
Good catch. Replicated and fixed. Thanks for the patch.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

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