about summary refs log tree commit homepage
path: root/lib/PublicInbox
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2020-01-01 03:28:22 +0000
committerEric Wong <e@80x24.org>2020-01-01 03:49:32 +0000
commit57c2bb80e2f94dfcbf08532f72c7ed568ceef7be (patch)
treee692347dba58a27b23c0d8f64ad80e51f46e3a75 /lib/PublicInbox
parent39f2513042482162c8bb855c67b3806786e3516e (diff)
downloadpublic-inbox-57c2bb80e2f94dfcbf08532f72c7ed568ceef7be.tar.gz
Time::Local has the concept of a "rolling century" which is
defined at 50 years on either side of the current year.  Since
it's now 2020 and >50 years since the Unix epoch, the year "70"
gets interpreted by Time::Local as 2070-01-01 instead of
1970-01-01.

Since NNTP servers are unlikely to store messages from the
future, we'll feed 4-digit year to Time::Local::{timegm,timelocal}
and hopefully not have to worry about things until Y10K.

This fixes test failures on t/v2writable.t and t/nntpd.t since
2020-01-01.
Diffstat (limited to 'lib/PublicInbox')
-rw-r--r--lib/PublicInbox/NNTP.pm11
1 files changed, 6 insertions, 5 deletions
diff --git a/lib/PublicInbox/NNTP.pm b/lib/PublicInbox/NNTP.pm
index 6845e872..95c9082d 100644
--- a/lib/PublicInbox/NNTP.pm
+++ b/lib/PublicInbox/NNTP.pm
@@ -220,16 +220,17 @@ sub parse_time ($$;$) {
                 $gmt =~ /\A(?:UTC|GMT)\z/i or die "GM invalid: $gmt";
                 $gmt = 1;
         }
-        my @now = $gmt ? gmtime : localtime;
         my ($YYYY, $MM, $DD);
         if (bytes::length($date) == 8) { # RFC 3977 allows YYYYMMDD
                 ($YYYY, $MM, $DD) = unpack('A4A2A2', $date);
         } else { # legacy clients send YYMMDD
-                ($YYYY, $MM, $DD) = unpack('A2A2A2', $date);
+                my $YY;
+                ($YY, $MM, $DD) = unpack('A2A2A2', $date);
+                my @now = $gmt ? gmtime : localtime;
                 my $cur_year = $now[5] + 1900;
-                if ($YYYY > $cur_year) {
-                        $YYYY += int($cur_year / 1000) * 1000 - 100;
-                }
+                my $cur_cent = int($cur_year / 100) * 100;
+                $YYYY = (($YY + $cur_cent) > $cur_year) ?
+                        ($YY + 1900) : ($YY + $cur_cent);
         }
         if ($gmt) {
                 timegm($ss, $mm, $hh, $DD, $MM - 1, $YYYY);