about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2015-08-20 02:30:26 +0000
committerEric Wong <e@80x24.org>2015-08-20 02:31:32 +0000
commit7245596edd0167791e7324c2d34b7fd340a4557c (patch)
tree13bcd7154586bede2f817008d8cea1b28a4d793c /lib
parent15782f34be59578fbec95c01f057bcf2d133414f (diff)
downloadpublic-inbox-7245596edd0167791e7324c2d34b7fd340a4557c.tar.gz
We don't need share duplicate logic across both files.
Diffstat (limited to 'lib')
-rw-r--r--lib/PublicInbox/Feed.pm5
-rw-r--r--lib/PublicInbox/View.pm17
2 files changed, 13 insertions, 9 deletions
diff --git a/lib/PublicInbox/Feed.pm b/lib/PublicInbox/Feed.pm
index 253eed2a..0b7ef7f8 100644
--- a/lib/PublicInbox/Feed.pm
+++ b/lib/PublicInbox/Feed.pm
@@ -5,7 +5,7 @@ use strict;
 use warnings;
 use Email::Address;
 use Email::MIME;
-use Date::Parse qw(strptime str2time);
+use Date::Parse qw(strptime);
 use PublicInbox::Hval;
 use PublicInbox::GitCatFile;
 use PublicInbox::View;
@@ -70,9 +70,6 @@ sub generate_html_index {
                         $state = [ $ctx->{srch}, {}, $commit, 0 ];
                 }
                 my $mime = do_cat_mail($git, $_[0]) or return 0;
-                my $t = eval { str2time($mime->header('Date')) };
-                defined($t) or $t = 0;
-                $mime->header_set('X-PI-TS', $t);
                 $html .= PublicInbox::View->index_entry($mime, 0, $state);
                 1;
         });
diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index b3545a4a..4a8e54aa 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -97,11 +97,14 @@ sub index_entry {
         }
 
         my $ts = $mime->header('X-PI-TS');
-        my $fmt = '%Y-%m-%d %H:%M UTC';
+        unless (defined $ts) {
+                $ts = msg_timestamp($mime);
+        }
+        my $fmt = '%Y-%m-%d %H:%M';
         $ts = POSIX::strftime($fmt, gmtime($ts));
 
         $rv .= "$pfx<b\nid=\"$id\">$subj</b>\n$pfx";
-        $rv .= "- by $from @ $ts - ";
+        $rv .= "- by $from @ $ts UTC - ";
         $rv .= "<a\nid=\"s$midx\"\nhref=\"#s$next\">next</a>";
         if ($prev >= 0) {
                 $rv .= "/<a\nhref=\"#s$prev\">prev</a>";
@@ -583,13 +586,17 @@ sub load_results {
                         Email::MIME->new($str);
                 };
                 unless ($@) {
-                        my $t = eval { str2time($mime->header('Date')) };
-                        defined($t) or $t = 0;
-                        $mime->header_set('X-PI-TS', $t);
+                        $mime->header_set('X-PI-TS', msg_timestamp($mime));
                         push @msgs, $mime;
                 }
         }
         \@msgs;
 }
 
+sub msg_timestamp {
+        my ($mime) = @_;
+        my $ts = eval { str2time($mime->header('Date')) };
+        defined($ts) ? $ts : 0;
+}
+
 1;