]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1046213: datetime_from() generates wrong dates if year < 1901
authorFrédéric Buclin <LpSolit@gmail.com>
Mon, 8 Sep 2014 10:32:24 +0000 (12:32 +0200)
committerFrédéric Buclin <LpSolit@gmail.com>
Mon, 8 Sep 2014 10:32:24 +0000 (12:32 +0200)
r=sgreen a=glob

Bugzilla/Util.pm

index fa74ee60415d09bcdf4bc0735c766c775b94b048..be65b46c65515a57a33a791ae30644824ac7fcf2 100644 (file)
@@ -566,10 +566,14 @@ sub datetime_from {
 
     return undef if !@time;
 
-    # strptime() counts years from 1900, and months from 0 (January).
-    # We have to fix both values.
+    # strptime() counts years from 1900, except if they are older than 1901
+    # in which case it returns the full year (so 1890 -> 1890, but 1984 -> 84,
+    # and 3790 -> 1890). We make a guess and assume that 1100 <= year < 3000.
+    $time[5] += 1900 if $time[5] < 1100;
+
     my %args = (
-        year   => $time[5] + 1900,
+        year   => $time[5],
+        # Months start from 0 (January).
         month  => $time[4] + 1,
         day    => $time[3],
         hour   => $time[2],