summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: f968bb9)
raw | patch | inline | side by side (parent: f968bb9)
author | Igor Peshansky <igorpeshansky@github.com> | |
Thu, 15 Sep 2016 19:30:15 +0000 (15:30 -0400) | ||
committer | Igor Peshansky <igorpeshansky@github.com> | |
Thu, 15 Sep 2016 19:32:36 +0000 (15:32 -0400) |
- Repurpose rfc3339()/rfc3339nano() to return time in zulu format.
- Add formatted time examples to function comments.
- Clean up helper functions and add variable iniitalization.
- Add formatted time examples to function comments.
- Clean up helper functions and add variable iniitalization.
src/daemon/utils_time.c | patch | blob | history | |
src/daemon/utils_time.h | patch | blob | history |
index 36ee8f2ae60ebf682633426ceb0bf61be9b2c47d..77c1b6882f174761a4aa7b83ebf896a0856a654b 100644 (file)
--- a/src/daemon/utils_time.c
+++ b/src/daemon/utils_time.c
Formatting functions
***********************************************************************/
-static const char utc_zone[] = "+00:00";
static const char zulu_zone[] = "Z";
/* format_zone reads time zone information from "extern long timezone", exported
@@ -186,22 +185,22 @@ int format_rfc3339 (char *buffer, size_t buffer_size, struct tm const *t_tm, lon
return 0;
} /* }}} int format_rfc3339 */
-int format_rfc3339_utc (char *buffer, size_t buffer_size, cdtime_t t, _Bool print_nano, char const *zone) /* {{{ */
+int format_rfc3339_utc (char *buffer, size_t buffer_size, cdtime_t t, _Bool print_nano) /* {{{ */
{
struct tm t_tm;
- long nsec;
+ long nsec = 0;
int status;
if ((status = get_utc_time (t, &t_tm, &nsec)) != 0)
return status; /* The error should have already be reported. */
- return format_rfc3339 (buffer, buffer_size, &t_tm, nsec, print_nano, zone);
+ return format_rfc3339 (buffer, buffer_size, &t_tm, nsec, print_nano, zulu_zone);
} /* }}} int format_rfc3339_utc */
int format_rfc3339_local (char *buffer, size_t buffer_size, cdtime_t t, _Bool print_nano) /* {{{ */
{
struct tm t_tm;
- long nsec;
+ long nsec = 0;
int status;
char zone[7]; /* +00:00 */
if (buffer_size < RFC3339_SIZE)
return ENOMEM;
- return format_rfc3339_utc (buffer, buffer_size, t, 0, utc_zone);
+ return format_rfc3339_utc (buffer, buffer_size, t, 0);
} /* }}} int rfc3339 */
int rfc3339nano (char *buffer, size_t buffer_size, cdtime_t t) /* {{{ */
if (buffer_size < RFC3339NANO_SIZE)
return ENOMEM;
- return format_rfc3339_utc (buffer, buffer_size, t, 1, utc_zone);
+ return format_rfc3339_utc (buffer, buffer_size, t, 1);
} /* }}} int rfc3339nano */
-int rfc3339_zulu (char *buffer, size_t buffer_size, cdtime_t t) /* {{{ */
-{
- if (buffer_size < RFC3339_ZULU_SIZE)
- return ENOMEM;
-
- return format_rfc3339_utc (buffer, buffer_size, t, 0, zulu_zone);
-} /* }}} int rfc3339_zulu */
-
-int rfc3339nano_zulu (char *buffer, size_t buffer_size, cdtime_t t) /* {{{ */
-{
- if (buffer_size < RFC3339NANO_ZULU_SIZE)
- return ENOMEM;
-
- return format_rfc3339_utc (buffer, buffer_size, t, 1, zulu_zone);
-} /* }}} int rfc3339nano_zulu */
-
int rfc3339_local (char *buffer, size_t buffer_size, cdtime_t t) /* {{{ */
{
if (buffer_size < RFC3339_SIZE)
index 5456dcc142053a3a619afcecc79171dc576dd7a5..7834723917587a9e1837ef29a72e373f08c90f3d 100644 (file)
--- a/src/daemon/utils_time.h
+++ b/src/daemon/utils_time.h
#define RFC3339_SIZE 26 /* 2006-01-02T15:04:05+00:00 */
#define RFC3339NANO_SIZE 36 /* 2006-01-02T15:04:05.999999999+00:00 */
-#define RFC3339_ZULU_SIZE 21 /* 2006-01-02T15:04:05Z */
-#define RFC3339NANO_ZULU_SIZE 31 /* 2006-01-02T15:04:05.999999999Z */
-
-/* rfc3339 formats a cdtime_t time as UTC in RFC 3339 format with second
- * precision. */
+/* rfc3339 formats a cdtime_t time as UTC in RFC 3339 zulu format with second
+ * precision, e.g., "2006-01-02T15:04:05Z". */
int rfc3339 (char *buffer, size_t buffer_size, cdtime_t t);
-/* rfc3339nano formats a cdtime_t as UTC time in RFC 3339 format with
- * nanosecond precision. */
+/* rfc3339nano formats a cdtime_t as UTC time in RFC 3339 zulu format with
+ * nanosecond precision, e.g., "2006-01-02T15:04:05.999999999Z". */
int rfc3339nano (char *buffer, size_t buffer_size, cdtime_t t);
-/* rfc3339 formats a cdtime_t time as UTC 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 as UTC in RFC 3339 zulu format with
- * nanosecond precision. */
-int rfc3339nano_zulu (char *buffer, size_t buffer_size, cdtime_t t);
-
/* rfc3339 formats a cdtime_t time as local in RFC 3339 format with second
- * precision. */
+ * precision, e.g., "2006-01-02T15:04:05+00:00". */
int rfc3339_local (char *buffer, size_t buffer_size, cdtime_t t);
/* rfc3339nano formats a cdtime_t time as local in RFC 3339 format with
- * nanosecond precision. */
+ * nanosecond precision, e.g., "2006-01-02T15:04:05.999999999+00:00". */
int rfc3339nano_local (char *buffer, size_t buffer_size, cdtime_t t);
#endif /* UTILS_TIME_H */