user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@yhbt.net>
To: meta@public-inbox.org
Subject: [PATCH 2/6] view: update POSIX::strftime usage
Date: Sun,  5 Jan 2020 23:23:32 +0000	[thread overview]
Message-ID: <20200105232336.26023-3-e@yhbt.net> (raw)
In-Reply-To: <20200105232336.26023-1-e@yhbt.net>

The POSIX module is always loaded, so import `strftime' into the
namespace so we can use it and take advantage of compile-time
arg checking.  While we're at it, update and reorder caller
functions to use prototypes, too.
---
 lib/PublicInbox/View.pm | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index 0d6f3351..e5cc475f 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -16,7 +16,7 @@ use PublicInbox::Address;
 use PublicInbox::WwwStream;
 use PublicInbox::Reply;
 use PublicInbox::ViewDiff qw(flush_diff);
-require POSIX;
+use POSIX qw(strftime);
 use Time::Local qw(timegm);
 use PublicInbox::SearchMsg qw(subject_normalized);
 use constant COLS => 72;
@@ -207,6 +207,9 @@ sub nr_to_s ($$$) {
 	$nr == 1 ? "$nr $singular" : "$nr $plural";
 }
 
+# human-friendly format
+sub fmt_ts ($) { strftime('%Y-%m-%d %k:%M', gmtime($_[0])) }
+
 # this is already inside a <pre>
 sub index_entry {
 	my ($smsg, $ctx, $more) = @_;
@@ -925,8 +928,6 @@ sub missing_thread {
 	PublicInbox::ExtMsg::ext_msg($ctx);
 }
 
-sub fmt_ts { POSIX::strftime('%Y-%m-%d %k:%M', gmtime($_[0])) }
-
 sub dedupe_subject {
 	my ($prev_subj, $subj, $val) = @_;
 
@@ -1158,10 +1159,8 @@ sub dump_topics {
 	200;
 }
 
-sub ts2str ($) {
-	my ($ts) = @_;
-	POSIX::strftime('%Y%m%d%H%M%S', gmtime($ts));
-}
+# only for the t= query parameter passed to overview DB
+sub ts2str ($) { strftime('%Y%m%d%H%M%S', gmtime($_[0])) };
 
 sub str2ts ($) {
 	my ($yyyy, $mon, $dd, $hh, $mm, $ss) = unpack('A4A2A2A2A2A2', $_[0]);

  parent reply	other threads:[~2020-01-05 23:23 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-05 23:23 [PATCH 0/6] various cleanups around use/require Eric Wong
2020-01-05 23:23 ` [PATCH 1/6] hval: export prurl and add prototype Eric Wong
2020-01-05 23:23 ` Eric Wong [this message]
2020-01-05 23:23 ` [PATCH 3/6] altid: use msgmap at compile time Eric Wong
2020-01-05 23:23 ` [PATCH 4/6] admin: do not lazy-load Inbox or Config packages Eric Wong
2020-01-05 23:23 ` [PATCH 5/6] treewide: "require" + "use" cleanup and docs Eric Wong
2020-01-05 23:23 ` [PATCH 6/6] syscall: modernize away from pre-Perl-5.6 conventions Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200105232336.26023-3-e@yhbt.net \
    --to=e@yhbt.net \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).