summaryrefslogtreecommitdiffstats
path: root/lib/timeutils.c
diff options
context:
space:
mode:
authorSami Kerola2016-06-19 22:43:40 +0200
committerSami Kerola2016-06-26 22:58:18 +0200
commitc1616946825e7f4ae9769e2846e9ad63a7ba369c (patch)
treee13a75af86ebbed9210c563a22fa55a3cc59b63d /lib/timeutils.c
parentutmpdump: use always UTC-0 timezone in textual output (diff)
downloadkernel-qcow2-util-linux-c1616946825e7f4ae9769e2846e9ad63a7ba369c.tar.gz
kernel-qcow2-util-linux-c1616946825e7f4ae9769e2846e9ad63a7ba369c.tar.xz
kernel-qcow2-util-linux-c1616946825e7f4ae9769e2846e9ad63a7ba369c.zip
libcommon: add ISO_8601_GMTIME that will print UTC-0 timestamps
When timestamps are intented to be conversable back from string to binary it is best to stick with UTC-0 timezone. This is needed in utmpdump(1). Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'lib/timeutils.c')
-rw-r--r--lib/timeutils.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/lib/timeutils.c b/lib/timeutils.c
index 25a163e41..fd9aa3e2e 100644
--- a/lib/timeutils.c
+++ b/lib/timeutils.c
@@ -396,7 +396,12 @@ static int format_iso_time(struct tm *tm, suseconds_t usec, int flags, char *buf
/* timeval to ISO 8601 */
int strtimeval_iso(struct timeval *tv, int flags, char *buf, size_t bufsz)
{
- struct tm tm = *localtime(&tv->tv_sec);
+ struct tm tm;
+
+ if (flags & ISO_8601_GMTIME)
+ tm = *gmtime(&tv->tv_sec);
+ else
+ tm = *localtime(&tv->tv_sec);
return format_iso_time(&tm, tv->tv_usec, flags, buf, bufsz);
}
@@ -409,7 +414,12 @@ int strtm_iso(struct tm *tm, int flags, char *buf, size_t bufsz)
/* time_t to ISO 8601 */
int strtime_iso(const time_t *t, int flags, char *buf, size_t bufsz)
{
- struct tm tm = *localtime(t);
+ struct tm tm;
+
+ if (flags & ISO_8601_GMTIME)
+ tm = *gmtime(t);
+ else
+ tm = *localtime(t);
return format_iso_time(&tm, 0, flags, buf, bufsz);
}