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");
+}