On 16 February 2016 at 10:29, Karel Zak <kzak@xxxxxxxxxx> wrote: > On Thu, Feb 11, 2016 at 07:48:40PM -0500, J William Piggott wrote: >> - 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? 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. -- Sami Kerola http://www.iki.fi/kerolasa/ -- To unsubscribe from this list: send the line "unsubscribe util-linux" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html