All of lore.kernel.org
 help / color / mirror / Atom feed
From: J William Piggott <elseifthen@gmx.com>
To: Karel Zak <kzak@redhat.com>
Cc: util-linux@vger.kernel.org
Subject: [PATCH 1/1] hwclock.c, hwclock.8.in: new --show format
Date: Thu, 11 Feb 2016 19:48:40 -0500	[thread overview]
Message-ID: <56BD2BE8.3030501@gmx.com> (raw)
In-Reply-To: <56BD2A87.30009@gmx.com>


* hwclock.c: change --get and --show functions to the ISO 8601
  format and concatenate fractional seconds to the time display.

* hwclock.8.in: document this.

Signed-off-by: J William Piggott <elseifthen@gmx.com>
---
 sys-utils/hwclock.8.in |  8 +++-----
 sys-utils/hwclock.c    | 16 +++++++++-------
 2 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/sys-utils/hwclock.8.in b/sys-utils/hwclock.8.in
index d72b7a8..eddb864 100644
--- a/sys-utils/hwclock.8.in
+++ b/sys-utils/hwclock.8.in
@@ -88,16 +88,14 @@ command, such as \%'11\ minute\ mode' or from dual-booting another OS.
 .TQ
 .B \-\-get
 .br
-Read the Hardware Clock and print the time on standard output.
+Read the Hardware Clock and print its time to standard output in the
+.B ISO 8601
+format.
 The time shown is always in local time, even if you keep your Hardware Clock
 in UTC.  See the
 .B \%\-\-localtime
 option.
 .sp
-The time shown is in same format as that of 
-.BR \%date (1)
-by default, and additionally, the number of microseconds is shown.
-.sp 
 Showing the Hardware Clock time is the default when no function is specified.
 .sp
 The
diff --git a/sys-utils/hwclock.c b/sys-utils/hwclock.c
index 2eb21ac..6f14081 100644
--- a/sys-utils/hwclock.c
+++ b/sys-utils/hwclock.c
@@ -687,13 +687,15 @@ display_time(const bool hclock_valid, struct timeval hwctime)
 		       "either invalid (e.g. 50th day of month) or beyond the range "
 		       "we can handle (e.g. Year 2095)."));
 	else {
-		struct tm *lt;
-		char *format = "%c";
-		char ctime_now[200];
-
-		lt = localtime(&hwctime.tv_sec);
-		strftime(ctime_now, sizeof(ctime_now), format, lt);
-		printf(_("%s and %06d microseconds\n"), ctime_now, (int)hwctime.tv_usec);
+		struct tm lt;
+		int zhour, zmin;
+
+		lt = *localtime(&hwctime.tv_sec);
+		zhour = - timezone / 60 / 60;
+		zmin = abs(timezone / 60 % 60);
+		printf(_("%4d-%.2d-%.2d %02d:%02d:%02d.%06d%+02d:%02d\n"),
+		       lt.tm_year + 1900, lt.tm_mon + 1, lt.tm_mday, lt.tm_hour,
+		       lt.tm_min, lt.tm_sec, (int)hwctime.tv_usec, zhour, zmin);
 	}
 }
 

  reply	other threads:[~2016-02-12  0:48 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-12  0:42 [PATCH 0/1] hwclock --show format J William Piggott
2016-02-12  0:48 ` J William Piggott [this message]
2016-02-16 10:29   ` [PATCH 1/1] hwclock.c, hwclock.8.in: new " Karel Zak
2016-02-16 13:54     ` Sami Kerola
2016-02-16 20:13     ` Ruediger Meier
2016-02-17  2:02     ` J William Piggott
2016-02-17  2:20       ` Ruediger Meier
2016-02-17 10:54       ` Karel Zak
2016-02-17 11:05         ` 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=56BD2BE8.3030501@gmx.com \
    --to=elseifthen@gmx.com \
    --cc=kzak@redhat.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.