]> Sergey Matveev's repositories - public-inbox.git/commitdiff
msgtime: deal with strange minutes in TZ offsets
authorEric Wong <e@80x24.org>
Mon, 25 Nov 2019 05:24:54 +0000 (05:24 +0000)
committerEric Wong <e@80x24.org>
Wed, 27 Nov 2019 01:49:52 +0000 (01:49 +0000)
I'm not sure if TZ minute offsets aside from '00' or '30' exist,
but lets just deal with them properly when negative.  Examples
taken from various inboxes on lore.kernel.org.  These are mostly
message from spammers, but some are legitimate messages.

lib/PublicInbox/MsgTime.pm
t/msgtime.t

index 58e11d726a5cc23ca81618e6efd51333e4daac85..7dec48ce9d989841d731a3d52b4b220fe9028735 100644 (file)
@@ -23,6 +23,10 @@ sub str2date_zone ($) {
        my $sign = ($off < 0) ? '-' : '+';
        my $hour = abs(int($off / 3600));
        my $min  = ($off / 60) % 60;
+
+       # deal with weird offsets like '-0420' properly
+       $min = 60 - $min if ($min && $off < 0);
+
        my $zone = sprintf('%s%02d%02d', $sign, $hour, $min);
 
        # "-1200" is the furthest westermost zone offset,
index f969fa25f6aa5f1bd22ed739544c40494ab93d40..cecbb921f596ca56d171af263a19ab28f84ee3ee 100644 (file)
@@ -92,4 +92,9 @@ is_datestamp('Tue, 3 Jun 2003 8:58:23 --500', [1054648703, '-0500']);
 is_datestamp('Thu, 18 May 100 10:40:43 +0200 (MET DST)', [958639243, '+0200']);
 is_datestamp('Thu, 18 May 2000 10:40:43 +0200', [958639243, '+0200']);
 is_datestamp('Tue, 27 Feb 2007 16:23:25 -0060', [1172597005, '-0100']);
+is_datestamp('Wed, 20 Dec 2006 05:32:58 -0420', [1166608378, '-0420']);
+is_datestamp('Wed, 20 Dec 2006 05:32:58 +0420', [1166577178, '+0420']);
+is_datestamp('Thu, 14 Dec 2006 00:20:24 +0480', [1166036424, '+0520']);
+is_datestamp('Thu, 14 Dec 2006 00:20:24 -0480', [1166074824, '-0520']);
+is_datestamp('Mon, 14 Apr 2014 07:59:01 -0007', [1397462761, '-0007']);
 done_testing();