X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FMsgTime.pm;h=5ee087fd50fea18612798d094046b4ada12d16e1;hb=23af251dd607c4e75ab1e68063f2c885c48cc035;hp=479aaa4ecf132f5176d49ce54db6171769872666;hpb=b474aff922a07da7c4d9db00dec9cebb4744aa8c;p=public-inbox.git
diff --git a/lib/PublicInbox/MsgTime.pm b/lib/PublicInbox/MsgTime.pm
index 479aaa4e..5ee087fd 100644
--- a/lib/PublicInbox/MsgTime.pm
+++ b/lib/PublicInbox/MsgTime.pm
@@ -1,4 +1,4 @@
-# Copyright (C) 2018-2019 all contributors
+# Copyright (C) 2018-2021 all contributors
# License: AGPL-3.0+
# Various date/time-related functions
@@ -38,7 +38,7 @@ sub str2date_zone ($) {
if ($date =~ /(?:[A-Za-z]+,?\s+)? # day-of-week
([0-9]+),?\s+ # dd
([A-Za-z]+)\s+ # mon
- ([0-9]{2,})\s+ # YYYY or YY (or YYY :P)
+ ([0-9]{2,4})\s+ # YYYY or YY (or YYY :P)
([0-9]+)[:\.] # HH:
((?:[0-9]{2})|(?:\s?[0-9])) # MM
(?:[:\.]((?:[0-9]{2})|(?:\s?[0-9])))? # :SS
@@ -67,6 +67,10 @@ sub str2date_zone ($) {
$ts = timegm($ss // 0, $mm, $hh, $dd, $mon, $yyyy);
+ # 4-digit dates in non-spam from 1900s and 1910s exist in
+ # lore archives
+ return if $ts < 0;
+
# Compute the time offset from [+-]HHMM
$tz //= 0;
my ($tz_hh, $tz_mm);
@@ -91,7 +95,7 @@ sub str2date_zone ($) {
$sign = '+' if $off == 0;
$zone = sprintf('%s%02d%02d', $sign, $tz_hh, $tz_mm);
- # Time::Zone and Date::Parse are part of the same distibution,
+ # Time::Zone and Date::Parse are part of the same distribution,
# and we need Time::Zone to deal with tz names like "EDT"
} elsif (eval { require Date::Parse }) {
$ts = Date::Parse::str2time($date);
@@ -100,7 +104,8 @@ sub str2date_zone ($) {
# off is the time zone offset in seconds from GMT
my ($ss,$mm,$hh,$day,$month,$year,$off) =
Date::Parse::strptime($date);
- return undef unless(defined $off);
+ return unless defined($year);
+ $off //= 0;
# Compute the time zone from offset
my $sign = ($off < 0) ? '-' : '+';
@@ -133,7 +138,7 @@ sub time_response ($) {
}
sub msg_received_at ($) {
- my ($hdr) = @_; # Email::MIME::Header
+ my ($hdr) = @_; # PublicInbox::Eml
my @recvd = $hdr->header_raw('Received');
my ($ts);
foreach my $r (@recvd) {
@@ -148,7 +153,7 @@ sub msg_received_at ($) {
}
sub msg_date_only ($) {
- my ($hdr) = @_; # Email::MIME::Header
+ my ($hdr) = @_; # PublicInbox::Eml
my @date = $hdr->header_raw('Date');
my ($ts);
foreach my $d (@date) {
@@ -162,21 +167,21 @@ sub msg_date_only ($) {
}
# Favors Received header for sorting globally
-sub msg_timestamp ($) {
- my ($hdr) = @_; # Email::MIME::Header
+sub msg_timestamp ($;$) {
+ my ($hdr, $fallback) = @_; # PublicInbox::Eml
my $ret;
$ret = msg_received_at($hdr) and return time_response($ret);
$ret = msg_date_only($hdr) and return time_response($ret);
- wantarray ? (time, '+0000') : time;
+ time_response([ $fallback // time, '+0000' ]);
}
# Favors the Date: header for display and sorting within a thread
-sub msg_datestamp ($) {
- my ($hdr) = @_; # Email::MIME::Header
+sub msg_datestamp ($;$) {
+ my ($hdr, $fallback) = @_; # PublicInbox::Eml
my $ret;
$ret = msg_date_only($hdr) and return time_response($ret);
$ret = msg_received_at($hdr) and return time_response($ret);
- wantarray ? (time, '+0000') : time;
+ time_response([ $fallback // time, '+0000' ]);
}
1;