public inbox for util-linux@vger.kernel.org
 help / color / mirror / Atom feed
From: Sami Kerola <kerolasa@iki.fi>
To: util-linux@vger.kernel.org
Cc: kerolasa@iki.fi
Subject: [PATCH 13/16] last: use ISO 8601 time format for --fulltimes
Date: Sat, 17 Aug 2013 19:15:18 +0100	[thread overview]
Message-ID: <1376763321-22782-14-git-send-email-kerolasa@iki.fi> (raw)
In-Reply-To: <1376763321-22782-1-git-send-email-kerolasa@iki.fi>

The ISO 8601 format allows easy time stamp parsing, it tells which
timezone the clock is represented, and this format makes sorting and
searching very easy.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 login-utils/last.1 |  2 +-
 login-utils/last.c | 23 +++++++++++++++++------
 2 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/login-utils/last.1 b/login-utils/last.1
index eff6fe4..c7d2aa6 100644
--- a/login-utils/last.1
+++ b/login-utils/last.1
@@ -92,7 +92,7 @@ specify that time with
 and look for "still logged in".
 .TP
 \fB\-F\fR, \fB\-\-fulltimes\fR
-Print full login and logout times and dates.
+Print full login and logout times and dates in ISO 8601 format.
 .TP
 \fB\-R\fR, \fB\-\-nohostname\fR
 Suppresses the display of the hostname field.
diff --git a/login-utils/last.c b/login-utils/last.c
index e94f1f0..24a752c 100644
--- a/login-utils/last.c
+++ b/login-utils/last.c
@@ -253,6 +253,7 @@ static int dns_lookup(char *result, int size, int useip, int32_t *a)
 static int list(struct utmp *p, time_t t, int what)
 {
 	time_t		secs, tmp;
+	struct tm	*tm;
 	char		logintime[32];
 	char		logouttime[32];
 	char		length[32];
@@ -291,10 +292,13 @@ static int list(struct utmp *p, time_t t, int what)
 	 *	Calculate times
 	 */
 	tmp = (time_t)p->ut_time;
-	strcpy(logintime, ctime(&tmp));
-	if (fulltime)
-		sprintf(logouttime, "- %s", ctime(&t));
-	else {
+	if (fulltime) {
+		tm = localtime(&tmp);
+		strftime(logintime, sizeof(logintime), "%Y-%m-%dT%H:%M:%S%z", tm);
+		tm = localtime(&t);
+		strftime(logouttime, sizeof(logouttime), "- %Y-%m-%dT%H:%M:%S%z", tm);
+	} else {
+		strcpy(logintime, ctime(&tmp));
 		logintime[16] = 0;
 		sprintf(logouttime, "- %s", ctime(&t) + 11);
 		logouttime[7] = 0;
@@ -804,8 +808,15 @@ int main(int argc, char **argv)
 		}
 	}
 
-	printf(_("\n%s begins %s"), basename(ufile), ctime(&begintime));
-
+	printf(_("\n%s begins "), basename(ufile));
+	if (fulltime) {
+		char t[32];
+		struct tm *tm;
+		tm = localtime(&begintime);
+		strftime(t, sizeof(t), "%Y-%m-%dT%H:%M:%S%z", tm);
+		puts(t);
+	} else
+		fputs(ctime(&begintime), stdout);
 	fclose(fp);
 	return EXIT_SUCCESS;
 }
-- 
1.8.3.4


  parent reply	other threads:[~2013-08-17 18:16 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-17 18:15 [PATCH 00/16] pull: additions recent to last(1) work, plus few small changes Sami Kerola
2013-08-17 18:15 ` [PATCH 01/16] build-sys: remove unnecessary environment variable Sami Kerola
2013-08-17 18:15 ` [PATCH 02/16] docs: update TODO Sami Kerola
2013-08-17 18:15 ` [PATCH 03/16] build-sys: complete elvtune removal Sami Kerola
2013-08-17 18:15 ` [PATCH 04/16] docs: be clear which last(1) is deprecated Sami Kerola
2013-08-17 18:15 ` [PATCH 05/16] docs: add long options to last.1 manual page Sami Kerola
2013-08-17 18:15 ` [PATCH 06/16] include: carefulput: print determined char when unprintable char is found Sami Kerola
2013-08-17 18:15 ` [PATCH 07/16] last: use carefulput() for printable character output Sami Kerola
2013-08-17 18:15 ` [PATCH 08/16] last: check expected numeric user input is number Sami Kerola
2013-08-17 18:15 ` [PATCH 09/16] last: make switch cases complete, and inform if impossible occurs Sami Kerola
2013-08-17 18:15 ` [PATCH 10/16] last: prefer enum rather than #definition list Sami Kerola
2013-08-17 18:15 ` [PATCH 11/16] last: remove broken code Sami Kerola
2013-08-17 18:15 ` [PATCH 12/16] last: use as narrow variable scoping as possible Sami Kerola
2013-08-17 18:15 ` Sami Kerola [this message]
2013-08-17 18:15 ` [PATCH 14/16] last: global variables are initialize automatically to zero Sami Kerola
2013-08-17 18:15 ` [PATCH 15/16] last: allow --file to be defined multiple times Sami Kerola
2013-08-17 18:15 ` [PATCH 16/16] last: add --present option Sami Kerola
2013-08-23 10:07 ` [PATCH 00/16] pull: additions recent to last(1) work, plus few small changes Karel Zak
2013-08-23 10:42   ` Sami Kerola
2013-08-23 11:04     ` Karel Zak
2013-08-23 11:08     ` Karel Zak

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

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

  git send-email \
    --in-reply-to=1376763321-22782-14-git-send-email-kerolasa@iki.fi \
    --to=kerolasa@iki.fi \
    --cc=util-linux@vger.kernel.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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox