Address more review comments:
authorIgor Peshansky <igorpeshansky@github.com>
Thu, 15 Sep 2016 19:30:15 +0000 (15:30 -0400)
committerIgor 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.

src/daemon/utils_time.c
src/daemon/utils_time.h

index 36ee8f2..77c1b68 100644 (file)
@@ -128,7 +128,6 @@ static int get_local_time (cdtime_t t, struct tm *t_tm, long *nsec) /* {{{ */
  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 */
 
@@ -223,7 +222,7 @@ int rfc3339 (char *buffer, size_t buffer_size, cdtime_t t) /* {{{ */
   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) /* {{{ */
@@ -231,25 +230,9 @@ 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 5456dcc..7834723 100644 (file)
@@ -85,31 +85,20 @@ cdtime_t cdtime (void);
 #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 */