From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 5A0AF1F46C; Mon, 25 Nov 2019 05:24:55 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Cc: "Eric W. Biederman" Subject: [PATCH 3/3] msgtime: deal with strange minutes in TZ offsets Date: Mon, 25 Nov 2019 05:24:54 +0000 Message-Id: <20191125052454.19950-4-e@80x24.org> In-Reply-To: <20191125052454.19950-1-e@80x24.org> References: <20191125052454.19950-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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 | 4 ++++ t/msgtime.t | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/lib/PublicInbox/MsgTime.pm b/lib/PublicInbox/MsgTime.pm index 58e11d72..7dec48ce 100644 --- a/lib/PublicInbox/MsgTime.pm +++ b/lib/PublicInbox/MsgTime.pm @@ -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, diff --git a/t/msgtime.t b/t/msgtime.t index f969fa25..cecbb921 100644 --- a/t/msgtime.t +++ b/t/msgtime.t @@ -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();