user/dev discussion of public-inbox itself
 help / Atom feed
* [PATCH 0/2] searchmsg: ->date correctness
@ 2016-12-17 11:53 Eric Wong
  2016-12-17 11:53 ` [PATCH 1/2] searchmsg: remove locale-dependency for ->date Eric Wong
  2016-12-17 11:53 ` [PATCH 2/2] searchmsg: do not memoize {date} field Eric Wong
  0 siblings, 2 replies; 3+ messages in thread
From: Eric Wong @ 2016-12-17 11:53 UTC (permalink / raw)
  To: meta

Initially, I thought this accessor method was not needed at
all, but then I realized XHDR uses it to get a list of dates.
So, it's made locale-independent by avoiding strftime, as well
as no longer time wasting space since ->date is only called
once.

 lib/PublicInbox/SearchMsg.pm | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)


^ permalink raw reply	[flat|threaded] 3+ messages in thread

* [PATCH 1/2] searchmsg: remove locale-dependency for ->date
  2016-12-17 11:53 [PATCH 0/2] searchmsg: ->date correctness Eric Wong
@ 2016-12-17 11:53 ` Eric Wong
  2016-12-17 11:53 ` [PATCH 2/2] searchmsg: do not memoize {date} field Eric Wong
  1 sibling, 0 replies; 3+ messages in thread
From: Eric Wong @ 2016-12-17 11:53 UTC (permalink / raw)
  To: meta

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


^ permalink raw reply	[flat|threaded] 3+ messages in thread

* [PATCH 2/2] searchmsg: do not memoize {date} field
  2016-12-17 11:53 [PATCH 0/2] searchmsg: ->date correctness Eric Wong
  2016-12-17 11:53 ` [PATCH 1/2] searchmsg: remove locale-dependency for ->date Eric Wong
@ 2016-12-17 11:53 ` Eric Wong
  1 sibling, 0 replies; 3+ messages in thread
From: Eric Wong @ 2016-12-17 11:53 UTC (permalink / raw)
  To: meta

We only generate the ->date once in NNTP, so creating
the hash entry is a waste.
---
 lib/PublicInbox/SearchMsg.pm | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/lib/PublicInbox/SearchMsg.pm b/lib/PublicInbox/SearchMsg.pm
index 57fec16..9f3e27f 100644
--- a/lib/PublicInbox/SearchMsg.pm
+++ b/lib/PublicInbox/SearchMsg.pm
@@ -77,13 +77,10 @@ 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;
 	my ($sec, $min, $hour, $mday, $mon, $year, $wday) = gmtime($ts);
-	$self->{date} = "$DoW[$wday], ".
-			sprintf("%02d $MoY[$mon] %04d %02d:%02d:%02d +0000",
+	"$DoW[$wday], " . sprintf("%02d $MoY[$mon] %04d %02d:%02d:%02d +0000",
 				$mday, $year+1900, $hour, $min, $sec);
 
 }
-- 
EW


^ permalink raw reply	[flat|threaded] 3+ messages in thread

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-17 11:53 [PATCH 0/2] searchmsg: ->date correctness Eric Wong
2016-12-17 11:53 ` [PATCH 1/2] searchmsg: remove locale-dependency for ->date Eric Wong
2016-12-17 11:53 ` [PATCH 2/2] searchmsg: do not memoize {date} field Eric Wong

user/dev discussion of public-inbox itself

Archives are clonable:
	git clone --mirror http://public-inbox.org/meta
	git clone --mirror http://czquwvybam4bgbro.onion/meta
	git clone --mirror http://hjrcffqmbrq6wope.onion/meta
	git clone --mirror http://ou63pmih66umazou.onion/meta

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.mail.public-inbox.meta
	nntp://ou63pmih66umazou.onion/inbox.comp.mail.public-inbox.meta
	nntp://czquwvybam4bgbro.onion/inbox.comp.mail.public-inbox.meta
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.mail.public-inbox.meta
	nntp://news.gmane.org/gmane.mail.public-inbox.general

 note: .onion URLs require Tor: https://www.torproject.org/
       or Tor2web: https://www.tor2web.org/

AGPL code for this site: git clone https://public-inbox.org/ public-inbox