-# Copyright (C) 2018-2020 all contributors <meta@public-inbox.org>
+# Copyright (C) 2018-2021 all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
# Various date/time-related functions
$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);
# 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) ? '-' : '+';
}
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) {
}
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) {
}
# 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;