hwclock: use locale-specific date output format
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
db43d3d418
commit
319b8bb355
@ -60,25 +60,31 @@ static void show_clock(const char **pp_rtcname, int utc)
|
|||||||
#if SHOW_HWCLOCK_DIFF
|
#if SHOW_HWCLOCK_DIFF
|
||||||
struct timeval sys_tv;
|
struct timeval sys_tv;
|
||||||
#endif
|
#endif
|
||||||
time_t t;
|
time_t t = read_rtc(pp_rtcname, &sys_tv, utc);
|
||||||
char *cp;
|
|
||||||
|
|
||||||
t = read_rtc(pp_rtcname, &sys_tv, utc);
|
#if ENABLE_LOCALE_SUPPORT
|
||||||
cp = ctime(&t);
|
/* Standard hwclock uses locale-specific output format */
|
||||||
|
char cp[64];
|
||||||
|
struct tm *ptm = localtime(&t);
|
||||||
|
strftime(cp, sizeof(cp), "%c", ptm);
|
||||||
|
#else
|
||||||
|
char *cp = ctime(&t);
|
||||||
strchrnul(cp, '\n')[0] = '\0';
|
strchrnul(cp, '\n')[0] = '\0';
|
||||||
|
#endif
|
||||||
|
|
||||||
#if !SHOW_HWCLOCK_DIFF
|
#if !SHOW_HWCLOCK_DIFF
|
||||||
printf("%s 0.000000 seconds\n", cp);
|
printf("%s 0.000000 seconds\n", cp);
|
||||||
#else
|
#else
|
||||||
{
|
{
|
||||||
long diff = sys_tv.tv_sec - t;
|
long diff = sys_tv.tv_sec - t;
|
||||||
if (diff < 0 /*&& tv.tv_usec != 0*/) {
|
if (diff < 0 /*&& tv.tv_usec != 0*/) {
|
||||||
/* Why? */
|
/* Why we need diff++? */
|
||||||
/* diff >= 0 is ok: diff < 0, can't just use tv.tv_usec: */
|
/* diff >= 0 is ok: | diff < 0, can't just use tv.tv_usec: */
|
||||||
/* 45.520820 43.520820 */
|
/* 45.520820 | 43.520820 */
|
||||||
/* - 44.000000 - 45.000000 */
|
/* - 44.000000 | - 45.000000 */
|
||||||
/* = 1.520820 = -1.479180, not -2.520820! */
|
/* = 1.520820 | = -1.479180, not -2.520820! */
|
||||||
diff++;
|
diff++;
|
||||||
/* should be 1000000 - tv.tv_usec, but then we must check tv.tv_usec != 0 */
|
/* Should be 1000000 - tv.tv_usec, but then we must check tv.tv_usec != 0 */
|
||||||
sys_tv.tv_usec = 999999 - sys_tv.tv_usec;
|
sys_tv.tv_usec = 999999 - sys_tv.tv_usec;
|
||||||
}
|
}
|
||||||
printf("%s %ld.%06lu seconds\n", cp, diff, (unsigned long)sys_tv.tv_usec);
|
printf("%s %ld.%06lu seconds\n", cp, diff, (unsigned long)sys_tv.tv_usec);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user