hwclock --show format
cover hwclock --show format
The following commit is incorrect.
_______________________
commit dadaad018721a82aafc06af2e94c1c2f8cef68de
Author: Anna Jonna Ã<81>rmannsdóttir <[email protected]> Date: Thu Jan 28 19:03:20 2016 +0000
Change of output format and documentation.
_______________________
RE: hwclock.8.in changes
hwclock --show does not use the date(1) format, it uses strftime(3) %c.
Under POSIX date(1) format has a specific definition. In the glibc locale database it is set to the keyword date_fmt; hwclock uses strftime(3) %c format which is keyword d_t_fmt. For example:
LC_TIME=en_HK locale -k date_fmt d_t_fmt
date_fmt="%a %b %e %H:%M:%S %Z %Y"
d_t_fmt="%A, %B %d, %Y %p%I:%M:%S %Z"
LC_TIME=en_US locale -k date_fmt d_t_fmt
date_fmt="%a %b %e %H:%M:%S %Z %Y"
d_t_fmt="%a %d %b %Y %r %Z"
For the above locales date(1) format is the same, but hwclock(8) (strftime %c) is very different:
LC_TIME=en_HK date; LC_TIME=en_US date
Thu Feb 11 16:58:23 EST 2016
Thu Feb 11 16:58:23 EST 2016
LC_TIME=en_HK /sbin/hwclock; LC_TIME=en_US /sbin/hwclock Thursday, February 11, 2016 PM04:59:34 EST .559820 seconds Thu 11 Feb 2016 04:59:35 PM EST .004092 seconds
RE: hwclock.c changes:
OLD: Thu 11 Feb 2016 03:41:17 PM EST .490796 seconds
NEW: Thu 11 Feb 2016 03:40:55 PM EST and 000850 microseconds
"hwclock --show" is supposed to display the Hardware Clock time; it is not a dialog. Adding more and longer words, IMO, is not a improvement. (There also should not have been any zero padding.)
The apparent purpose of this change is to address the ambiguity created by having the fractional seconds separate from the time display. In the past it had to be that way, because the fractional part was always negative and did not wrap on overflow. After fixing that, I intended to concatenate the fractional part to the time display; using the %c format made doing so non-trivial. I wanted to change to a different format, but I had assumed that there would be push back against it. So the task went to the bottom of my TODO list.
Now that a format change has already been committed, I will go with that and submit a further change to ISO 8601.
RATIONAL
As hwclock is a system administration tool having its --show function in the ISO 8601 format is appropriate because:
* the format should be machine friendly
* the format should be conducive to logging
* the format should be conducive for timestamping
* it should use a predictable, locale independent, international format
* it does not need to pretty print because:
* it cannot be called by a normal user
* it is not used for wallclock time
PULL REQUEST INFORMATION
The following changes since commit 583627ef363f0e0bd8a7dac646507c2458accc56:
agetty: add support for \e in issue file to print \033 (2016-02-11 12:33:57 +0100)
are available in the git repository at:
[email protected]:jwpi/util-linux.git 020716
for you to fetch changes up to 0c0d33d1f6d564fdc16a655edecda38db74bce0e:
hwclock.c, hwclock.8.in: new --show format (2016-02-11 16:02:05 -0500)
----------------------------------------------------------------
J William Piggott (1):
hwclock.c, hwclock.8.in: new --show format
sys-utils/hwclock.8.in | 8 +++----- sys-utils/hwclock.c | 16 +++++++++------- 2 files changed, 12 insertions(+), 12 deletions(-)
PATCH 1/1 hwclock.c, hwclock.8.in: new --show format
* 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.
--- sys-utils/hwclock.8.in | 8 +++----- sys-utils/hwclock.c | 16 +++++++++------- 2 files changed, 12 insertions(+), 12 deletions(-)
sys-utils/hwclock.8.in +3 -5
@@ -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
sys-utils/hwclock.c +9 -7
@@ -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); } }
Karel Zak
maintainerRe: [PATCH 1/1] hwclock.c, hwclock.8.in: new --show format
sys-utils/hwclock.c display_time(const bool hclock_valid, struct timeval hwctime) · line 698
Quoted 12 lines · J William Piggott
sys-utils/hwclock.c +9
-3- 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);
Some notes:
* what's wrong with strftime?
* We already use ISO time in util-linux and we use time designator 'T' (separator between date and time).
* tv_usec is "long"
* fraction separator is decimal mark, either a comma or a dot, but with a preference for a comma according to ISO 8601:2004 (wikipedia).
-- we already use comma in util-linux, exception is logger where I see dot :-(
Anyway, it would be really nice to have a function for this purpose in lib/timeutils.c to avoid duplication and creativity :-) Something like:
strtime_iso_8601(char buf, size_t bufsz, struct tm tm, struct timeval frac, int flags);
where flags are
enum {
ISO_8601_TIMEZONE = (1 << 1)
ISO_8601_USEC = (1 << 2)
...
};then we can use this function in lslogins, dmesg, hwclock, last, logger, ... etc. I can also imagine:
strtime_short_ctime()
strtime_ctime() (ctime without \n)
Comments?
Karel
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com
Re: [PATCH 1/1] hwclock.c, hwclock.8.in: new --show format
Quoted 45 lines · Karel Zak
sys-utils/hwclock.c display_time(const bool hclock_valid, struct timeval hwctime) · line 698
Quoted 12 lines · J William Piggott
sys-utils/hwclock.c +9
-3- 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);Some notes:
* what's wrong with strftime?
* We already use ISO time in util-linux and we use time designator 'T' (separator between date and time).
*
tv_usecis "long"* fraction separator is decimal mark, either a comma or a dot, but with a preference for a comma according to ISO 8601:2004 (wikipedia).
-- we already use comma in util-linux, exception is logger where I see dot :-(
Anyway, it would be really nice to have a function for this purpose in
lib/timeutils.cto avoid duplication and creativity :-) Something like:strtime_iso_8601(char buf, size_t bufsz, struct tm tm, struct timeval frac, int flags);where flags are
enum { ISO_8601_TIMEZONE = (1 << 1) ISO_8601_USEC = (1 << 2) ... };
Quoted 7 lines
then we can use this function in lslogins, dmesg, hwclock, last, logger, ... etc. I can also imagine:
strtime_short_ctime()
strtime_ctime()(ctime without \n)Comments?
Logger is special, it is using Internet date/time format, see 5.8. Examples.
https://www.ietf.org/rfc/rfc3339.txt
And when I read the ISO 8601 from wikipedia
https://en.wikipedia.org/wiki/ISO_8601#Times
there is: A decimal mark, either a comma or a dot (without any preference as stated in resolution 10 of the 22nd General Conference CGPM in 2003, but with a preference for a comma according to ISO 8601:2004)
So one hopes date parser authors will accept either.
Signature · 2 lines
Sami Kerola http://www.iki.fi/kerolasa/
Re: [PATCH 1/1] hwclock.c, hwclock.8.in: new --show format
In reply to Karel ZakQuoted 16 lines · Karel Zak
sys-utils/hwclock.c display_time(const bool hclock_valid, struct timeval hwctime) · line 698
Quoted 12 lines · J William Piggott
sys-utils/hwclock.c +0
-3- 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;
sys-utils/hwclock.c +8
-0+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);Some notes:
Quoted 1 line
* what's wrong with strftime?
For me strftime always "sounds" locale and system dependent. If we don't want to use locale anyways then I would prefer printf to make this clear for the reader.
On the other hand if someone knows that our choosen ISO style is portable and locale independent implemented in any system's strftime, ok to use strftime then.
Quoted 2 lines
* We already use ISO time in util-linux and we use time designator 'T' (separator between date and time).
I know that "T" is the best compromise. Anyways for humans I try to use space if possible. It simply looks better. IMO more important is that any parser code would accept space as well as 'T'.
Quoted 8 lines
*
tv_usecis "long"* fraction separator is decimal mark, either a comma or a dot, but with a preference for a comma according to ISO 8601:2004 (wikipedia).
-- we already use comma in util-linux, exception is logger where I see dot :-(
Where do we use comma? Usually I would prefer dot (for decimal fractions of seconds). I guess most people use dot and would be confused about comma. Existing software may more likely not accept comma. Like this example
https://github.com/moment/moment/issues/2580
Quoted 25 lines
Anyway, it would be really nice to have a function for this purpose in
lib/timeutils.cto avoid duplication and creativity :-) Something like:strtime_iso_8601(char buf,
size_tbufsz, struct tm tm, struct
timeval frac, int flags);where flags are
enum { ISO_8601_TIMEZONE = (1 << 1) ISO_8601_USEC = (1 << 2) ... };then we can use this function in lslogins, dmesg, hwclock, last, logger, ... etc. I can also imagine:
strtime_short_ctime()
strtime_ctime()(ctime without \n)Comments?
Karel
Re: [PATCH 1/1] hwclock.c, hwclock.8.in: new --show format
In reply to Karel ZakQuoted 16 lines · Karel Zak
sys-utils/hwclock.c display_time(const bool hclock_valid, struct timeval hwctime) · line 698
Quoted 12 lines · J William Piggott
sys-utils/hwclock.c +9
-3- 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);Some notes:
Quoted 1 line
* what's wrong with strftime?
Why use resources on strftime when 8601 prints directly?
While it can do other formatting, I see strftime's main purpose as converting tm numbers into strings like: January, Monday, etc.
Quoted 3 lines
* We already use ISO time in util-linux and we use time designator 'T' (separator between date and time).
I chose to use the optional space as a compromise between machine friendly and human friendly, this is commonly done I think.
Quoted 2 lines
*
tv_usecis "long"
Fixed: I followed the example from the recent commit c211401 (for code consistency, which is why I originally used the int cast), and cast it to long; although I do not understand why as it is already long. All that needed to be done was to change the conversion length modifier and drop the cast.
PULL:
[email protected]:jwpi/util-linux.git 020716
for you to fetch changes up to e05ac5aae00913e7a999c96a7bb731dc1d09cc5c:
Quoted 7 lines
* fraction separator is decimal mark, either a comma or a dot, but with a preference for a comma according to ISO 8601:2004 (wikipedia).
-- we already use comma in util-linux, exception is logger where I see dot :-(
I actually modeled the format after:
date --rfc-3339=ns
2016-02-16 20:13:25.601508440-05:00
3339 is a subset of 8601 that requires using a period for the radix point. As I said previously, I chose this as a compromise between machine and human readability. As it is output to tty by default, I thought doing so might mitigate any push back against the format change.
I am not strongly opposed to using 'T' as the date-time delimiter or comma as the radix point. I just think 'space' and 'period' are a commonly used compromise.
Quoted 16 lines
Anyway, it would be really nice to have a function for this purpose in
lib/timeutils.cto avoid duplication and creativity :-) Something like:strtime_iso_8601(char buf, size_t bufsz, struct tm tm, struct timeval frac, int flags);where flags are
enum { ISO_8601_TIMEZONE = (1 << 1) ISO_8601_USEC = (1 << 2) ... };
Quoted 7 lines
then we can use this function in lslogins, dmesg, hwclock, last, logger, ... etc. I can also imagine:
strtime_short_ctime()
strtime_ctime()(ctime without \n)Comments?
Also, perhaps all the above only using something similar to coreutil's fprintftime, so it prints directly using less resources.
Quoted 3 lines
Karel
Re: [PATCH 1/1] hwclock.c, hwclock.8.in: new --show format
Quoted 31 lines · J William Piggott
Quoted 17 lines · Karel Zak
Quoted 11 lines · J William Piggott
sys-utils/hwclock.c +0
-3- 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;
sys-utils/hwclock.c +7
-0+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,Quoted 2 lines
lt.tm_hour, + lt.tm_min, lt.tm_sec, (int)hwctime.tv_usec,
zhour, zmin);Some notes:
Quoted 1 line
* what's wrong with strftime?
Why use resources on strftime when 8601 prints directly?
While it can do other formatting, I see strftime's main purpose as converting tm numbers into strings like: January, Monday, etc.
Quoted 2 lines
* We already use ISO time in util-linux and we use time designator 'T' (separator between date and time).
I chose to use the optional space as a compromise between machine friendly and human friendly, this is commonly done I think.
Quoted 7 lines
Quoted 1 line
*
tv_usecis "long"Fixed: I followed the example from the recent commit c211401 (for code consistency, which is why I originally used the int cast), and cast it to long; although I do not understand why as it is already long. All that needed to be done was to change the conversion length modifier and drop the cast.
It's not long on all systems, e.g.__darwin_suseconds_t is int. Casting to long seems to be the way to avoid warnings everywhere.
Quoted 5 lines
PULL:
[email protected]:jwpi/util-linux.git 020716
for you to fetch changes up to
e05ac5aae00913e7a999c96a7bb731dc1d09cc5c:
Quoted 55 lines
Quoted 6 lines
* fraction separator is decimal mark, either a comma or a dot, but with a preference for a comma according to ISO 8601:2004 (wikipedia).
-- we already use comma in util-linux, exception is logger where
I see dot :-(I actually modeled the format after:
date --rfc-3339=ns
2016-02-16 20:13:25.601508440-05:003339 is a subset of 8601 that requires using a period for the radix point. As I said previously, I chose this as a compromise between machine and human readability. As it is output to tty by default, I thought doing so might mitigate any push back against the format change.
I am not strongly opposed to using 'T' as the date-time delimiter or comma as the radix point. I just think 'space' and 'period' are a commonly used compromise.
Quoted 16 lines
Anyway, it would be really nice to have a function for this purpose in
lib/timeutils.cto avoid duplication and creativity :-) Something like:strtime_iso_8601(char buf,
size_tbufsz, struct tm tm, struct
timeval frac, int flags);where flags are
enum { ISO_8601_TIMEZONE = (1 << 1) ISO_8601_USEC = (1 << 2) ... };Quoted 7 lines
then we can use this function in lslogins, dmesg, hwclock, last, logger, ... etc. I can also imagine:
strtime_short_ctime()
strtime_ctime()(ctime without \n)Comments?
Also, perhaps all the above only using something similar to coreutil's fprintftime, so it prints directly using less resources.
Quoted 1 line
Karel
--
To unsubscribe from this list: send the line "unsubscribe util-linux" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Karel Zak
maintainerRe: [PATCH 1/1] hwclock.c, hwclock.8.in: new --show format
In reply to J William PiggottQuoted 18 lines · J William Piggott
Quoted 16 lines · Karel Zak
sys-utils/hwclock.c display_time(const bool hclock_valid, struct timeval hwctime) · line 698
Quoted 12 lines · J William Piggott
sys-utils/hwclock.c +9
-3- 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);Some notes:
Quoted 6 lines
Quoted 1 line
* what's wrong with strftime?
Why use resources on strftime when 8601 prints directly?
While it can do other formatting, I see strftime's main purpose as converting tm numbers into strings like: January, Monday, etc.
It does more things for you, see lt.tm_year + 1900, lt.tm_mon + 1, calculation of the time zone hours, timezone minutes...
Quoted 17 lines
Quoted 17 lines
Anyway, it would be really nice to have a function for this purpose in
lib/timeutils.cto avoid duplication and creativity :-) Something like:strtime_iso_8601(char buf, size_t bufsz, struct tm tm, struct timeval frac, int flags);where flags are
enum { ISO_8601_TIMEZONE = (1 << 1) ISO_8601_USEC = (1 << 2) ... };then we can use this function in lslogins, dmesg, hwclock, last, logger, ... etc. I can also imagine:
Quoted 7 lines
Quoted 4 lines
strtime_short_ctime()
strtime_ctime()(ctime without \n)Comments?
Also, perhaps all the above only using something similar to coreutil's fprintftime, so it prints directly using less resources.
Well, things don't end after commit. Someone has to maintain it for years and for example now we have many places where we produces the same time format. So, I'd like to keep it on one place and minimize differences in formatting.
I'll merge your patch and cleanup the things later...
Karel
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com
Karel Zak
maintainerRe: [PATCH 1/1] hwclock.c, hwclock.8.in: new --show format
Quoted 21 lines · Karel Zak
Quoted 20 lines · J William Piggott
Quoted 17 lines · Karel Zak
sys-utils/hwclock.c display_time(const bool hclock_valid, struct timeval hwctime) · line 698
Quoted 12 lines · J William Piggott
sys-utils/hwclock.c +9
-3- 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);Some notes:
* what's wrong with strftime?
Quoted 7 lines
Quoted 4 lines
Why use resources on strftime when 8601 prints directly?
While it can do other formatting, I see strftime's main purpose as converting tm numbers into strings like: January, Monday, etc.
It does more things for you, see lt.tm_year + 1900, lt.tm_mon + 1, calculation of the time zone hours, timezone minutes...
Ah, now I see that strftime is not able to produce timezone hh:mm. Well, compose the string without strftime seems better in this case. Sorry.
Karel
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com