708da5
From 381d51822fccaa333cbd0ab9fca8b69f650c05f9 Mon Sep 17 00:00:00 2001
708da5
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
708da5
Date: Fri, 14 Feb 2020 14:10:10 +0100
708da5
Subject: [PATCH] Only pass 2-digit years to tests when testing 2-digit year
708da5
 handling
708da5
MIME-Version: 1.0
708da5
Content-Type: text/plain; charset=UTF-8
708da5
Content-Transfer-Encoding: 8bit
708da5
708da5
This will start breaking in 2020 if done without working around the whole
708da5
breakpoint thing. See https://rt.cpan.org/Ticket/Display.html?id=124787.
708da5
708da5
Ported from Time-Local 63265fd81c7f6177bf28dfe0d1ada9cb897de566 commit
708da5
by Dave Rolsky <autarch@urth.org> to perl 5.28.2.
708da5
708da5
Signed-off-by: Petr Písař <ppisar@redhat.com>
708da5
---
708da5
 cpan/Time-Local/t/Local.t | 40 +++++++++++++++++++++++++++++----------
708da5
 1 file changed, 30 insertions(+), 10 deletions(-)
708da5
708da5
diff --git a/cpan/Time-Local/t/Local.t b/cpan/Time-Local/t/Local.t
708da5
index 6341396..701d22d 100644
708da5
--- a/cpan/Time-Local/t/Local.t
708da5
+++ b/cpan/Time-Local/t/Local.t
708da5
@@ -85,19 +85,17 @@ my $epoch_is_64
708da5
 
708da5
 for ( @time, @neg_time ) {
708da5
     my ( $year, $mon, $mday, $hour, $min, $sec ) = @$_;
708da5
-    $year -= 1900;
708da5
     $mon--;
708da5
 
708da5
 SKIP: {
708da5
         skip '1970 test on VOS fails.', 12
708da5
-            if $^O eq 'vos' && $year == 70;
708da5
+            if $^O eq 'vos' && $year == 1970;
708da5
         skip 'this platform does not support negative epochs.', 12
708da5
-            if $year < 70 && !$neg_epoch_ok;
708da5
+            if $year < 1970 && !$neg_epoch_ok;
708da5
 
708da5
         # Test timelocal()
708da5
         {
708da5
-            my $year_in = $year < 70 ? $year + 1900 : $year;
708da5
-            my $time = timelocal( $sec, $min, $hour, $mday, $mon, $year_in );
708da5
+            my $time = timelocal( $sec, $min, $hour, $mday, $mon, $year );
708da5
 
708da5
             my ( $s, $m, $h, $D, $M, $Y ) = localtime($time);
708da5
 
708da5
@@ -106,13 +104,12 @@ SKIP: {
708da5
             is( $h, $hour,     "timelocal hour for @$_" );
708da5
             is( $D, $mday,     "timelocal day for @$_" );
708da5
             is( $M, $mon,      "timelocal month for @$_" );
708da5
-            is( $Y, $year,     "timelocal year for @$_" );
708da5
+            is( $Y, $year - 1900,     "timelocal year for @$_" );
708da5
         }
708da5
 
708da5
         # Test timegm()
708da5
         {
708da5
-            my $year_in = $year < 70 ? $year + 1900 : $year;
708da5
-            my $time = timegm( $sec, $min, $hour, $mday, $mon, $year_in );
708da5
+            my $time = timegm( $sec, $min, $hour, $mday, $mon, $year );
708da5
 
708da5
             my ( $s, $m, $h, $D, $M, $Y ) = gmtime($time);
708da5
 
708da5
@@ -121,14 +118,13 @@ SKIP: {
708da5
             is( $h, $hour,     "timegm hour for @$_" );
708da5
             is( $D, $mday,     "timegm day for @$_" );
708da5
             is( $M, $mon,      "timegm month for @$_" );
708da5
-            is( $Y, $year,     "timegm year for @$_" );
708da5
+            is( $Y, $year - 1900,     "timegm year for @$_" );
708da5
         }
708da5
     }
708da5
 }
708da5
 
708da5
 for (@bad_time) {
708da5
     my ( $year, $mon, $mday, $hour, $min, $sec ) = @$_;
708da5
-    $year -= 1900;
708da5
     $mon--;
708da5
 
708da5
     eval { timegm( $sec, $min, $hour, $mday, $mon, $year ) };
708da5
@@ -229,6 +225,30 @@ SKIP:
708da5
     );
708da5
 }
708da5
 
708da5
+# 2-digit years
708da5
+{
708da5
+	my $current_year = ( localtime() )[5];
708da5
+	my $pre_break    = ( $current_year + 49 ) - 100;
708da5
+	my $break        = ( $current_year + 50 ) - 100;
708da5
+	my $post_break   = ( $current_year + 51 ) - 100;
708da5
+
708da5
+	is(
708da5
+		( ( localtime( timelocal( 0, 0, 0, 1, 1, $pre_break ) ) )[5] ),
708da5
+		$pre_break + 100,
708da5
+		"year $pre_break is treated as next century",
708da5
+	);
708da5
+	is(
708da5
+		( ( localtime( timelocal( 0, 0, 0, 1, 1, $break ) ) )[5] ),
708da5
+		$break + 100,
708da5
+		"year $break is treated as next century",
708da5
+	);
708da5
+	is(
708da5
+		( ( localtime( timelocal( 0, 0, 0, 1, 1, $post_break ) ) )[5] ),
708da5
+		$post_break,
708da5
+		"year $post_break is treated as current century",
708da5
+	);
708da5
+}
708da5
+
708da5
 SKIP:
708da5
 {
708da5
     skip 'These tests only run for the package maintainer.', 8
708da5
-- 
708da5
2.21.1
708da5