chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
man: mention docker as type of virtualization
[elogind.git]
/
src
/
shared
/
time-util.c
diff --git
a/src/shared/time-util.c
b/src/shared/time-util.c
index 066ef973ac88d64e4a512d9743b03aca9534c53f..09f4a21354c5eedba4df460cb66f5ec5bb54b6ea 100644
(file)
--- a/
src/shared/time-util.c
+++ b/
src/shared/time-util.c
@@
-152,7
+152,7
@@
struct timeval *timeval_store(struct timeval *tv, usec_t u) {
return tv;
}
return tv;
}
-char *format_timestamp
(char *buf, size_t l, usec_t t
) {
+char *format_timestamp
_internal(char *buf, size_t l, usec_t t, bool utc
) {
struct tm tm;
time_t sec;
struct tm tm;
time_t sec;
@@
-164,13
+164,21
@@
char *format_timestamp(char *buf, size_t l, usec_t t) {
sec = (time_t) (t / USEC_PER_SEC);
sec = (time_t) (t / USEC_PER_SEC);
- if (strftime(buf, l, "%a %Y-%m-%d %H:%M:%S %Z", localtime_r(&sec, &tm)) <= 0)
+ if (utc)
+ gmtime_r(&sec, &tm);
+ else
+ localtime_r(&sec, &tm);
+ if (strftime(buf, l, "%a %Y-%m-%d %H:%M:%S %Z", &tm) <= 0)
return NULL;
return buf;
}
return NULL;
return buf;
}
-char *format_timestamp_us(char *buf, size_t l, usec_t t) {
+char *format_timestamp(char *buf, size_t l, usec_t t) {
+ return format_timestamp_internal(buf, l, t, false);
+}
+
+char *format_timestamp_us(char *buf, size_t l, usec_t t, bool utc) {
struct tm tm;
time_t sec;
struct tm tm;
time_t sec;
@@
-181,7
+189,10
@@
char *format_timestamp_us(char *buf, size_t l, usec_t t) {
return NULL;
sec = (time_t) (t / USEC_PER_SEC);
return NULL;
sec = (time_t) (t / USEC_PER_SEC);
- localtime_r(&sec, &tm);
+ if (utc)
+ gmtime_r(&sec, &tm);
+ else
+ localtime_r(&sec, &tm);
if (strftime(buf, l, "%a %Y-%m-%d %H:%M:%S", &tm) <= 0)
return NULL;
if (strftime(buf, l, "%a %Y-%m-%d %H:%M:%S", &tm) <= 0)
return NULL;