user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
* [PATCH 0/3] msgtime: tests and wonky offsets
@ 2019-11-25  5:24 Eric Wong
  2019-11-25  5:24 ` [PATCH 1/3] t/msgtime: show date in test descriptions Eric Wong
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Eric Wong @ 2019-11-25  5:24 UTC (permalink / raw)
  To: meta; +Cc: Eric W. Biederman

I've been working on making Date::Parse optional, but found
some existing bugs and improvements to test cases along the
way.

Eric Wong (3):
  t/msgtime: show date in test descriptions
  t/msgtime: add more checks for known cases
  msgtime: deal with strange minutes in TZ offsets

 lib/PublicInbox/MsgTime.pm |  4 ++++
 t/msgtime.t                | 31 ++++++++++++++++++++++---------
 2 files changed, 26 insertions(+), 9 deletions(-)


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/3] t/msgtime: show date in test descriptions
  2019-11-25  5:24 [PATCH 0/3] msgtime: tests and wonky offsets Eric Wong
@ 2019-11-25  5:24 ` Eric Wong
  2019-11-25  5:24 ` [PATCH 2/3] t/msgtime: add more checks for known cases Eric Wong
  2019-11-25  5:24 ` [PATCH 3/3] msgtime: deal with strange minutes in TZ offsets Eric Wong
  2 siblings, 0 replies; 4+ messages in thread
From: Eric Wong @ 2019-11-25  5:24 UTC (permalink / raw)
  To: meta; +Cc: Eric W. Biederman

Otherwise it's hard to figure what fails.
---
 t/msgtime.t | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/t/msgtime.t b/t/msgtime.t
index 6b396602..7bf73185 100644
--- a/t/msgtime.t
+++ b/t/msgtime.t
@@ -58,7 +58,7 @@ for (my $min = -1440; $min <= 1440; $min += 30) {
 	my $date = sprintf("Fri, 02 Oct 1993 00:00:00 %s%02d%02d",
 			   $sign, $h, $m);
 	my $result = datestamp($date);
-	is_deeply($result, [ $ts_expect, $tz_expect ]);
+	is_deeply($result, [ $ts_expect, $tz_expect ], $date);
 }
 
 # Verify that the parser sucks up the timezone and for received timestamps
@@ -74,14 +74,19 @@ for (my $min = -1440; $min <= 1440; $min += 30) {
 	}
 	my $received = sprintf('Mon, 22 Jan 2007 13:16:24 %s%02d%02d',
 			       $sign, $h, $m);
-	is_deeply(timestamp($received), [ $ts_expect, $tz_expect ]);
+	is_deeply(timestamp($received), [ $ts_expect, $tz_expect ],
+		$received);
 }
 
-is_deeply(datestamp('Wed, 13 Dec 2006 10:26:38 +1'), [1166001998, '+0100']);
-is_deeply(datestamp('Fri, 3 Feb 2006 18:11:22 -00'), [1138990282, '+0000']);
-is_deeply(datestamp('Thursday, 20 Feb 2003 01:14:34 +000'), [1045703674, '+0000']);
-is_deeply(datestamp('Fri, 28 Jun 2002 12:54:40 -700'), [1025294080, '-0700']);
-is_deeply(datestamp('Sat, 12 Jan 2002 12:52:57 -200'), [1010847177, '-0200']);
-is_deeply(datestamp('Mon, 05 Nov 2001 10:36:16 -800'), [1004985376, '-0800']);
+sub is_datestamp ($$) {
+	my ($date, $expect) = @_;
+	is_deeply(datestamp($date), $expect, $date);
+}
+is_datestamp('Wed, 13 Dec 2006 10:26:38 +1', [1166001998, '+0100']);
+is_datestamp('Fri, 3 Feb 2006 18:11:22 -00', [1138990282, '+0000']);
+is_datestamp('Thursday, 20 Feb 2003 01:14:34 +000', [1045703674, '+0000']);
+is_datestamp('Fri, 28 Jun 2002 12:54:40 -700', [1025294080, '-0700']);
+is_datestamp('Sat, 12 Jan 2002 12:52:57 -200', [1010847177, '-0200']);
+is_datestamp('Mon, 05 Nov 2001 10:36:16 -800', [1004985376, '-0800']);
 
 done_testing();

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/3] t/msgtime: add more checks for known cases
  2019-11-25  5:24 [PATCH 0/3] msgtime: tests and wonky offsets Eric Wong
  2019-11-25  5:24 ` [PATCH 1/3] t/msgtime: show date in test descriptions Eric Wong
@ 2019-11-25  5:24 ` Eric Wong
  2019-11-25  5:24 ` [PATCH 3/3] msgtime: deal with strange minutes in TZ offsets Eric Wong
  2 siblings, 0 replies; 4+ messages in thread
From: Eric Wong @ 2019-11-25  5:24 UTC (permalink / raw)
  To: meta; +Cc: Eric W. Biederman

Broken email clients sent the darndest things, make sure
we can still support them when we make Date::Parse optional.
---
 t/msgtime.t | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/t/msgtime.t b/t/msgtime.t
index 7bf73185..f969fa25 100644
--- a/t/msgtime.t
+++ b/t/msgtime.t
@@ -88,5 +88,8 @@ is_datestamp('Thursday, 20 Feb 2003 01:14:34 +000', [1045703674, '+0000']);
 is_datestamp('Fri, 28 Jun 2002 12:54:40 -700', [1025294080, '-0700']);
 is_datestamp('Sat, 12 Jan 2002 12:52:57 -200', [1010847177, '-0200']);
 is_datestamp('Mon, 05 Nov 2001 10:36:16 -800', [1004985376, '-0800']);
-
+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']);
 done_testing();

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 3/3] msgtime: deal with strange minutes in TZ offsets
  2019-11-25  5:24 [PATCH 0/3] msgtime: tests and wonky offsets Eric Wong
  2019-11-25  5:24 ` [PATCH 1/3] t/msgtime: show date in test descriptions Eric Wong
  2019-11-25  5:24 ` [PATCH 2/3] t/msgtime: add more checks for known cases Eric Wong
@ 2019-11-25  5:24 ` Eric Wong
  2 siblings, 0 replies; 4+ messages in thread
From: Eric Wong @ 2019-11-25  5:24 UTC (permalink / raw)
  To: meta; +Cc: Eric W. Biederman

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();

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-11-25  5:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-25  5:24 [PATCH 0/3] msgtime: tests and wonky offsets Eric Wong
2019-11-25  5:24 ` [PATCH 1/3] t/msgtime: show date in test descriptions Eric Wong
2019-11-25  5:24 ` [PATCH 2/3] t/msgtime: add more checks for known cases Eric Wong
2019-11-25  5:24 ` [PATCH 3/3] msgtime: deal with strange minutes in TZ offsets Eric Wong

Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).