This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Upgrade to Time::Local 1.16
authorRafael Garcia-Suarez <rgarciasuarez@gmail.com>
Wed, 24 Jan 2007 11:02:24 +0000 (11:02 +0000)
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>
Wed, 24 Jan 2007 11:02:24 +0000 (11:02 +0000)
p4raw-id: //depot/perl@29940

lib/Time/Local.pm
lib/Time/Local.t

index f5bb4bb..d80d6c8 100644 (file)
@@ -7,7 +7,7 @@ use strict;
 use integer;
 
 use vars qw( $VERSION @ISA @EXPORT @EXPORT_OK );
 use integer;
 
 use vars qw( $VERSION @ISA @EXPORT @EXPORT_OK );
-$VERSION   = '1.15';
+$VERSION   = '1.16';
 
 @ISA       = qw( Exporter );
 @EXPORT    = qw( timegm timelocal );
 
 @ISA       = qw( Exporter );
 @EXPORT    = qw( timegm timelocal );
@@ -91,9 +91,6 @@ sub _timegm {
 sub timegm {
     my ( $sec, $min, $hour, $mday, $month, $year ) = @_;
 
 sub timegm {
     my ( $sec, $min, $hour, $mday, $month, $year ) = @_;
 
-    # Need to check leap year before altering the value
-    my $leap_year = _is_leap_year($year);
-
     if ( $year >= 1000 ) {
         $year -= 1900;
     }
     if ( $year >= 1000 ) {
         $year -= 1900;
     }
@@ -114,7 +111,7 @@ sub timegm {
 
        my $md = $MonthDays[$month];
         ++$md
 
        my $md = $MonthDays[$month];
         ++$md
-            if $month == 1 && $leap_year;
+            if $month == 1 && _is_leap_year( $year + 1900 );
 
         croak "Day '$mday' out of range 1..$md"  if $mday > $md or $mday < 1;
         croak "Hour '$hour' out of range 0..23"  if $hour > 23  or $hour < 0;
 
         croak "Day '$mday' out of range 1..$md"  if $mday > $md or $mday < 1;
         croak "Hour '$hour' out of range 0..23"  if $hour > 23  or $hour < 0;
index 4ae7392..bba6796 100755 (executable)
@@ -77,7 +77,7 @@ my $tests = (@time * 12);
 $tests += @neg_time * 12;
 $tests += @bad_time;
 $tests += @years;
 $tests += @neg_time * 12;
 $tests += @bad_time;
 $tests += @years;
-$tests += 5;
+$tests += 10;
 $tests += 2 if $ENV{PERL_CORE};
 $tests += 8 if $ENV{MAINTAINER};
 
 $tests += 2 if $ENV{PERL_CORE};
 $tests += 8 if $ENV{MAINTAINER};
 
@@ -171,8 +171,25 @@ SKIP:
     skip 'this platform does not support negative epochs.', 1
         unless $neg_epoch_ok;
 
     skip 'this platform does not support negative epochs.', 1
         unless $neg_epoch_ok;
 
+    eval { timegm(0,0,0,29,1,1900) };
+    like($@, qr/Day '29' out of range 1\.\.28/,
+         'does not accept leap day in 1900');
+
+    eval { timegm(0,0,0,29,1,200) };
+    like($@, qr/Day '29' out of range 1\.\.28/,
+         'does not accept leap day in 2100 (year passed as 200)');
+
+    eval { timegm(0,0,0,29,1,0) };
+    is($@, '', 'no error with leap day of 2000 (year passed as 0)');
+
     eval { timegm(0,0,0,29,1,1904) };
     is($@, '', 'no error with leap day of 1904');
     eval { timegm(0,0,0,29,1,1904) };
     is($@, '', 'no error with leap day of 1904');
+
+    eval { timegm(0,0,0,29,1,4) };
+    is($@, '', 'no error with leap day of 2004 (year passed as 4)');
+
+    eval { timegm(0,0,0,29,1,96) };
+    is($@, '', 'no error with leap day of 1996 (year passed as 96)');
 }
 
 if ($ENV{MAINTAINER}) {
 }
 
 if ($ENV{MAINTAINER}) {