File perl-TimeDate-parse-out-century-if-specified.patch of Package perl-TimeDate.15487

From d7450983cbc7ea9d54662c9a181824d3e8bcfbf3 Mon Sep 17 00:00:00 2001
From: Jonathan Scott Duff <duff@pobox.com>
Date: Sun, 1 Mar 2015 23:43:25 -0600
Subject: [PATCH] [strptime] Parse out century if specified

If we've been given a year that's got the century attached (i.e., the
year is > 1900), store the century.  Then use this information to defeat
the guessing behavior of timegm.
---
 lib/Date/Parse.pm | 20 +++++++++++++-------
 t/cpanrt.t        |  2 +-
 2 files changed, 14 insertions(+), 8 deletions(-)

Index: TimeDate-2.30/lib/Date/Parse.pm
===================================================================
--- TimeDate-2.30.orig/lib/Date/Parse.pm
+++ TimeDate-2.30/lib/Date/Parse.pm
@@ -73,7 +73,7 @@ sub {
   my $dtstr = lc shift;
   my $merid = 24;
 
-  my($year,$month,$day,$hh,$mm,$ss,$zone,$dst,$frac);
+  my($century,$year,$month,$day,$hh,$mm,$ss,$zone,$dst,$frac);
 
   $zone = tz_offset(shift) if @_;
 
@@ -195,12 +195,15 @@ sub {
     }
   }
 
-  $year -= 1900 if defined $year && $year > 2000;
+  if (defined $year && $year > 1900) {
+    $century = int($year / 100);
+    $year -= 1900;
+  }
 
   $zone += 3600 if defined $zone && $dst;
   $ss += "0.$frac" if $frac;
 
-  return ($ss,$mm,$hh,$day,$month,$year,$zone);
+  return ($ss,$mm,$hh,$day,$month,$year,$zone,$century);
 }
 ESQ
 
@@ -233,7 +236,7 @@ sub str2time
  return undef
 	unless @t;
 
- my($ss,$mm,$hh,$day,$month,$year,$zone) = @t;
+ my($ss,$mm,$hh,$day,$month,$year,$zone, $century) = @t;
  my @lt  = localtime(time);
 
  $hh    ||= 0;
@@ -252,6 +255,9 @@ sub str2time
  $year = ($month > $lt[4]) ? ($lt[5] - 1) : $lt[5]
 	unless(defined $year);
 
+ # we were given a 4 digit year, so let's keep using those
+ $year += 1900 if defined $century;
+
  return undef
 	unless($month <= 11 && $day >= 1 && $day <= 31
 		&& $hh <= 23 && $mm <= 59 && $ss <= 59);
@@ -317,9 +323,9 @@ date string does not specify a timezone.
 =item strptime(DATE [, ZONE])
 
 C<strptime> takes the same arguments as str2time but returns an array of
-values C<($ss,$mm,$hh,$day,$month,$year,$zone)>. Elements are only defined
-if they could be extracted from the date string. The C<$zone> element is
-the timezone offset in seconds from GMT. An empty array is returned upon
+values C<($ss,$mm,$hh,$day,$month,$year,$zone,$century)>. Elements are only
+defined if they could be extracted from the date string. The C<$zone> element
+is the timezone offset in seconds from GMT. An empty array is returned upon
 failure.
 
 =head1 MULTI-LANGUAGE SUPPORT
Index: TimeDate-2.30/t/cpanrt.t
===================================================================
--- TimeDate-2.30.orig/t/cpanrt.t
+++ TimeDate-2.30/t/cpanrt.t
@@ -22,7 +22,7 @@ my $i = 1;
     my @t = strptime($str);
     my $t = join ":", map { defined($_) ? $_ : "-" } @t;
     print "# $str => $t\n";
-    print "not " unless $t eq "-:35:22:30:10:108:3600";
+    print "not " unless $t eq "-:35:22:30:10:108:3600:20";
     print "ok ", $i++, "\n";
   }
 }
openSUSE Build Service is sponsored by