summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 806091e)
raw | patch | inline | side by side (parent: 806091e)
author | Dave Cunningham <dcunnin@google.com> | |
Fri, 9 Sep 2016 02:19:16 +0000 (22:19 -0400) | ||
committer | Igor Peshansky <igorpeshansky@github.com> | |
Fri, 9 Sep 2016 02:50:52 +0000 (22:50 -0400) |
src/daemon/utils_time.c | patch | blob | history | |
src/daemon/utils_time.h | patch | blob | history |
index 86476ea63b4cd95728cfd843a48b52d26859d979..af51d037c48aef48d8114b8f7df4ca2023293ab7 100644 (file)
--- a/src/daemon/utils_time.c
+++ b/src/daemon/utils_time.c
@@ -112,7 +112,7 @@ static int format_zone (char *buffer, size_t buffer_size, struct tm const *tm) /
return 0;
} /* }}} int format_zone */
-static int format_rfc3339 (char *buffer, size_t buffer_size, cdtime_t t, _Bool print_nano) /* {{{ */
+static int format_rfc3339 (char *buffer, size_t buffer_size, cdtime_t t, _Bool print_nano, _Bool zulu) /* {{{ */
{
struct timespec t_spec;
struct tm t_tm;
@@ -126,12 +126,22 @@ static int format_rfc3339 (char *buffer, size_t buffer_size, cdtime_t t, _Bool p
CDTIME_T_TO_TIMESPEC (t, &t_spec);
NORMALIZE_TIMESPEC (t_spec);
- if (localtime_r (&t_spec.tv_sec, &t_tm) == NULL) {
- char errbuf[1024];
- status = errno;
- ERROR ("format_rfc3339: localtime_r failed: %s",
- sstrerror (status, errbuf, sizeof (errbuf)));
- return (status);
+ if (zulu) {
+ if (gmtime_r (&t_spec.tv_sec, &t_tm) == NULL) {
+ char errbuf[1024];
+ status = errno;
+ ERROR ("format_rfc3339: gmtime_r failed: %s",
+ sstrerror (status, errbuf, sizeof (errbuf)));
+ return (status);
+ }
+ } else {
+ if (localtime_r (&t_spec.tv_sec, &t_tm) == NULL) {
+ char errbuf[1024];
+ status = errno;
+ ERROR ("format_rfc3339: localtime_r failed: %s",
+ sstrerror (status, errbuf, sizeof (errbuf)));
+ return (status);
+ }
}
len = strftime (base, sizeof (base), "%Y-%m-%dT%H:%M:%S", &t_tm);
@@ -143,9 +153,14 @@ static int format_rfc3339 (char *buffer, size_t buffer_size, cdtime_t t, _Bool p
else
sstrncpy (nano, "", sizeof (nano));
- status = format_zone (zone, sizeof (zone), &t_tm);
- if (status != 0)
- return status;
+ if (zulu) {
+ zone[0] = 'Z';
+ zone[1] = 0;
+ } else {
+ status = format_zone (zone, sizeof (zone), &t_tm);
+ if (status != 0)
+ return status;
+ }
if (strjoin (buffer, buffer_size, fields, STATIC_ARRAY_SIZE (fields), "") < 0)
return ENOMEM;
if (buffer_size < RFC3339_SIZE)
return ENOMEM;
- return format_rfc3339 (buffer, buffer_size, t, 0);
+ return format_rfc3339 (buffer, buffer_size, t, 0, 0);
} /* }}} size_t cdtime_to_rfc3339 */
int rfc3339nano (char *buffer, size_t buffer_size, cdtime_t t) /* {{{ */
if (buffer_size < RFC3339NANO_SIZE)
return ENOMEM;
- return format_rfc3339 (buffer, buffer_size, t, 1);
+ return format_rfc3339 (buffer, buffer_size, t, 1, 0);
+} /* }}} size_t cdtime_to_rfc3339nano */
+
+int rfc3339_zulu (char *buffer, size_t buffer_size, cdtime_t t) /* {{{ */
+{
+ if (buffer_size < RFC3339_ZULU_SIZE)
+ return ENOMEM;
+
+ return format_rfc3339 (buffer, buffer_size, t, 0, 1);
+} /* }}} size_t cdtime_to_rfc3339 */
+
+int rfc3339nano_zulu (char *buffer, size_t buffer_size, cdtime_t t) /* {{{ */
+{
+ if (buffer_size < RFC3339NANO_ZULU_SIZE)
+ return ENOMEM;
+
+ return format_rfc3339 (buffer, buffer_size, t, 1, 1);
} /* }}} size_t cdtime_to_rfc3339nano */
/* vim: set sw=2 sts=2 et fdm=marker : */
index 4d88dccb6684ec3f4c823f3429ce5a9455d35e1a..29db9d2444f1cf2a3beb5b6e8f1d19cf8a316db4 100644 (file)
--- a/src/daemon/utils_time.h
+++ b/src/daemon/utils_time.h
#define RFC3339_SIZE 26
#define RFC3339NANO_SIZE 36
+#define RFC3339_ZULU_SIZE 21
+#define RFC3339NANO_ZULU_SIZE 31
+
/* rfc3339 formats a cdtime_t time in RFC 3339 format with second precision. */
int rfc3339 (char *buffer, size_t buffer_size, cdtime_t t);
* precision. */
int rfc3339nano (char *buffer, size_t buffer_size, cdtime_t t);
+/* rfc3339 formats a cdtime_t time in RFC 3339 zulu format with second
+ * precision. */
+int rfc3339_zulu (char *buffer, size_t buffer_size, cdtime_t t);
+
+/* rfc3339nano formats a cdtime_t time in RFC 3339 zulu format with nanosecond
+ * precision. */
+int rfc3339nano_zulu (char *buffer, size_t buffer_size, cdtime_t t);
+
#endif /* UTILS_TIME_H */
/* vim: set sw=2 sts=2 et : */