Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Email-Date-Format CPAN distribution.

Report information
The Basics
Id: 124530
Status: new
Priority: 0/
Queue: Email-Date-Format

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

Bug Information
Severity: Normal
Broken in: 1.005
Fixed in: (no value)



Subject: timegm should be called with 4-digit year
man Time::Local says Whenever possible, use an absolute four digit year instead. With a detailed explanation about ambiguity of 2-digit years above that. Please review/test/merge the attached patch - somewhat tested using the added test (as is it only fails in 2018 because that is 50 years after 1968)
Subject: fix.patch
Index: Email-Date-Format-1.005/lib/Email/Date/Format.pm =================================================================== --- Email-Date-Format-1.005.orig/lib/Email/Date/Format.pm +++ Email-Date-Format-1.005/lib/Email/Date/Format.pm @@ -54,8 +54,12 @@ use Time::Local (); sub _tz_diff { my ($time) = @_; - my $diff = Time::Local::timegm(localtime $time) - - Time::Local::timegm(gmtime $time); + my @localtime = localtime $time; + my @gmtime = gmtime $time; + $localtime[5] += 1900; + $gmtime[5] += 1900; + my $diff = Time::Local::timegm(@localtime) + - Time::Local::timegm(@gmtime); my $direc = $diff < 0 ? '-' : '+'; $diff = abs $diff; Index: Email-Date-Format-1.005/t/basic.t =================================================================== --- Email-Date-Format-1.005.orig/t/basic.t +++ Email-Date-Format-1.005/t/basic.t @@ -1,4 +1,4 @@ -use Test::More tests => 3; +use Test::More tests => 5; use strict; $^W = 1; @@ -29,3 +29,10 @@ is( 'Thu, 20 Jul 2006 21:58:24 +0000', "rjbs's birthday date format properly in GMT", ); + +{ local $ENV{TZ} = "UTC-11"; + $tz = sprintf "%s%02u%02u", Email::Date::Format::_tz_diff(-31536060); + is($tz, "+1100", "timezone before year rollover"); + $tz = sprintf "%s%02u%02u", Email::Date::Format::_tz_diff(-31532340); + is($tz, "+1100", "timezone after year rollover"); +}
From: bitcardbmw [...] lsmod.de
Show quoted text
> Please review/test/merge the attached patch - somewhat tested using > the added test (as is it only fails in 2018 because that is 50 years > after 1968)
Enhanced the new test to reliably fail at any time, even after 2050 (unless 4-digit years are used in the code)
Subject: fix.patch
Index: Email-Date-Format-1.005/lib/Email/Date/Format.pm =================================================================== --- Email-Date-Format-1.005.orig/lib/Email/Date/Format.pm +++ Email-Date-Format-1.005/lib/Email/Date/Format.pm @@ -54,8 +54,12 @@ use Time::Local (); sub _tz_diff { my ($time) = @_; - my $diff = Time::Local::timegm(localtime $time) - - Time::Local::timegm(gmtime $time); + my @localtime = localtime $time; + my @gmtime = gmtime $time; + $localtime[5] += 1900; + $gmtime[5] += 1900; + my $diff = Time::Local::timegm(@localtime) + - Time::Local::timegm(@gmtime); my $direc = $diff < 0 ? '-' : '+'; $diff = abs $diff; Index: Email-Date-Format-1.005/t/basic.t =================================================================== --- Email-Date-Format-1.005.orig/t/basic.t +++ Email-Date-Format-1.005/t/basic.t @@ -1,4 +1,4 @@ -use Test::More tests => 3; +use Test::More tests => 7; use strict; $^W = 1; @@ -12,7 +12,10 @@ is( my $birthday = 1153432704; # no, really! -my $tz = sprintf "%s%02u%02u", Email::Date::Format::_tz_diff(1153432704); +sub tz($) { sprintf "%s%02u%02u", Email::Date::Format::_tz_diff(shift) } + +local $ENV{TZ} = "UTC+4"; +my $tz = tz(1153432704); SKIP: { skip "test only useful in US/Eastern, -0400, not $tz", 1 if $tz ne '-0400'; @@ -29,3 +32,12 @@ is( 'Thu, 20 Jul 2006 21:58:24 +0000', "rjbs's birthday date format properly in GMT", ); + +my $badyear = 1900 + ((gmtime)[5] - 49) % 100; +my $badt = Time::Local::timegm(0, 0, 0, 1, 0, $badyear); +$ENV{TZ} = "UTC-11"; +is(tz($badt - 60), "+1100", "positive timezone before year rollover"); +is(tz($badt + 60), "+1100", "positive timezone after year rollover"); +$ENV{TZ} = "UTC+9"; +is(tz($badt - 60), "-0900", "negative timezone before year rollover"); +is(tz($badt + 60), "-0900", "negative timezone after year rollover");