From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-2.6 required=3.0 tests=AWL,BAYES_00, RCVD_IN_MSPIKE_BL,RCVD_IN_MSPIKE_ZBI,RCVD_IN_XBL,RDNS_NONE,SPF_FAIL, SPF_HELO_FAIL shortcircuit=no autolearn=no autolearn_force=no version=3.4.0 Received: from 80x24.org (unknown [85.248.227.165]) by dcvr.yhbt.net (Postfix) with ESMTP id 0D768203EA for ; Sat, 17 Dec 2016 11:53:34 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 1/2] searchmsg: remove locale-dependency for ->date Date: Sat, 17 Dec 2016 11:53:23 +0000 Message-Id: <20161217115324.27937-2-e@80x24.org> In-Reply-To: <20161217115324.27937-1-e@80x24.org> References: <20161217115324.27937-1-e@80x24.org> List-Id: strftime is locale-dependent, which can cause surprising failures for some users. --- lib/PublicInbox/SearchMsg.pm | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/PublicInbox/SearchMsg.pm b/lib/PublicInbox/SearchMsg.pm index 5779d1e..57fec16 100644 --- a/lib/PublicInbox/SearchMsg.pm +++ b/lib/PublicInbox/SearchMsg.pm @@ -12,7 +12,6 @@ use Date::Parse qw/str2time/; use PublicInbox::MID qw/mid_clean/; use PublicInbox::Address; our $PFX2TERM_RE = undef; -use POSIX qw(strftime); sub new { my ($class, $mime) = @_; @@ -72,13 +71,21 @@ sub subject ($) { __hdr($_[0], 'subject') } sub to ($) { __hdr($_[0], 'to') } sub cc ($) { __hdr($_[0], 'cc') } +# no strftime, that is locale-dependent +my @DoW = qw(Sun Mon Tue Wed Thu Fri Sat); +my @MoY = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); + sub date ($) { my ($self) = @_; my $date = __hdr($self, 'date'); return $date if defined $date; my $ts = $self->{ts}; return unless defined $ts; - $self->{date} = strftime('%a, %d %b %Y %T +0000', gmtime($ts)); + my ($sec, $min, $hour, $mday, $mon, $year, $wday) = gmtime($ts); + $self->{date} = "$DoW[$wday], ". + sprintf("%02d $MoY[$mon] %04d %02d:%02d:%02d +0000", + $mday, $year+1900, $hour, $min, $sec); + } sub from ($) { -- EW