#include <time.h>
#include "log.h"
+/*
+ * Careful with this; several of the conversion specification characters
+ * documented in the Linux man page are not actually portable.
+ */
+#define JSON_TS_FORMAT "%Y-%m-%dT%H:%M:%SZ"
+
int
json_get_str(json_t *parent, char const *name, char const **result)
{
return error;
memset(&tm, 0, sizeof(tm));
- consumed = strptime(str, "%FT%T%z", &tm);
+ consumed = strptime(str, JSON_TS_FORMAT, &tm);
if (consumed == NULL || (*consumed) != 0)
return pr_op_err("String '%s' does not appear to be a timestamp.",
str);
struct tm tmbuffer, *tm;
memset(&tmbuffer, 0, sizeof(tmbuffer));
- tm = localtime_r(&tt, &tmbuffer);
+ tm = gmtime_r(&tt, &tmbuffer);
if (tm == NULL)
return errno;
- if (strftime(str, sizeof(str) - 1, "%FT%T%z", tm) == 0)
+ if (strftime(str, sizeof(str) - 1, JSON_TS_FORMAT, tm) == 0)
return ENOSPC;
*result = json_string(str);
/* printf("%s\n", str); */
json_decref(json);
- /* TODO (test) Time zones are hardcoded to CST */
ck_assert_str_eq(
- "[{\"url\":\"rsync://a.b.c/d\",\"attempt-timestamp\":\"1969-12-31T18:00:00-0600\",\"attempt-result\":0,\"success-timestamp\":\"1969-12-31T18:00:00-0600\"},"
- "{\"url\":\"rsync://a.b.c/e\",\"attempt-timestamp\":\"1969-12-31T18:00:00-0600\",\"attempt-result\":1},"
- "{\"url\":\"rsync://x.y.z/e\",\"attempt-timestamp\":\"1969-12-31T18:00:00-0600\",\"attempt-result\":0,\"success-timestamp\":\"1969-12-31T18:00:00-0600\"},"
- "{\"url\":\"https://a/b\",\"attempt-timestamp\":\"1969-12-31T18:00:00-0600\",\"attempt-result\":1,\"success-timestamp\":\"1969-12-31T18:00:00-0600\"},"
- "{\"url\":\"https://a/c\",\"attempt-timestamp\":\"1969-12-31T18:00:00-0600\",\"attempt-result\":0,\"success-timestamp\":\"1969-12-31T18:00:00-0600\"}]",
+ "[{\"url\":\"rsync://a.b.c/d\",\"attempt-timestamp\":\"1970-01-01T00:00:00Z\",\"attempt-result\":0,\"success-timestamp\":\"1970-01-01T00:00:00Z\"},"
+ "{\"url\":\"rsync://a.b.c/e\",\"attempt-timestamp\":\"1970-01-01T00:00:00Z\",\"attempt-result\":1},"
+ "{\"url\":\"rsync://x.y.z/e\",\"attempt-timestamp\":\"1970-01-01T00:00:00Z\",\"attempt-result\":0,\"success-timestamp\":\"1970-01-01T00:00:00Z\"},"
+ "{\"url\":\"https://a/b\",\"attempt-timestamp\":\"1970-01-01T00:00:00Z\",\"attempt-result\":1,\"success-timestamp\":\"1970-01-01T00:00:00Z\"},"
+ "{\"url\":\"https://a/c\",\"attempt-timestamp\":\"1970-01-01T00:00:00Z\",\"attempt-result\":0,\"success-timestamp\":\"1970-01-01T00:00:00Z\"}]",
str);
printf("%s", str);
free(str);