Code

data: Use a predefined format for sdb_strftime().
authorSebastian Harl <sh@tokkee.org>
Wed, 20 May 2015 21:53:48 +0000 (23:53 +0200)
committerSebastian Harl <sh@tokkee.org>
Wed, 20 May 2015 21:53:48 +0000 (23:53 +0200)
Also, print the nanosecond fraction of a second.

src/core/data.c
src/core/store.c
src/core/store_json.c
src/core/time.c
src/include/core/time.h
src/parser/analyzer.c
t/unit/core/data_test.c
t/unit/core/store_json_test.c
t/unit/core/time_test.c
t/unit/frontend/query_test.c
t/unit/testutils.h

index 444f5a1c91053d7f30665603fccaea394281d33e..58c8b524e1111c662e7587aa5e1614d10d084b5d 100644 (file)
@@ -931,8 +931,8 @@ sdb_data_strlen(const sdb_data_t *datum)
                /* in the worst case, each character needs to be escaped */
                return 2 * strlen(datum->data.string) + 2;
        case SDB_TYPE_DATETIME:
-               /* "YYYY-MM-DD HH:MM:SS +zzzz" */
-               return 27;
+               /* "YYYY-MM-DD HH:MM:SS[.nnnnnnnnn] +zzzz" */
+               return 37;
        case SDB_TYPE_BINARY:
                if (! datum->data.binary.datum)
                        return 6; /* NULL */
@@ -1013,8 +1013,7 @@ sdb_data_format(const sdb_data_t *datum, char *buf, size_t buflen, int quoted)
                }
        }
        else if (datum->type == SDB_TYPE_DATETIME) {
-               if (! sdb_strftime(tmp, sizeof(tmp), "%F %T %z",
-                                       datum->data.datetime))
+               if (! sdb_strftime(tmp, sizeof(tmp), datum->data.datetime))
                        return -1;
                tmp[sizeof(tmp) - 1] = '\0';
                data = tmp;
index bf12a9378eb228e811a87ea268eb8fa403991672..171e31935bb898eefb5e6e95b46000a20f3cb1a6 100644 (file)
@@ -488,12 +488,10 @@ ts_tojson(sdb_timeseries_t *ts, sdb_strbuf_t *buf)
        size_t i;
 
        /* TODO: make time format configurable */
-       if (! sdb_strftime(start_str, sizeof(start_str),
-                               "%F %T %z", ts->start))
+       if (! sdb_strftime(start_str, sizeof(start_str), ts->start))
                snprintf(start_str, sizeof(start_str), "<error>");
        start_str[sizeof(start_str) - 1] = '\0';
-       if (! sdb_strftime(end_str, sizeof(end_str),
-                               "%F %T %z", ts->end))
+       if (! sdb_strftime(end_str, sizeof(end_str), ts->end))
                snprintf(end_str, sizeof(end_str), "<error>");
        end_str[sizeof(end_str) - 1] = '\0';
 
@@ -507,8 +505,7 @@ ts_tojson(sdb_timeseries_t *ts, sdb_strbuf_t *buf)
                for (j = 0; j < ts->data_len; ++j) {
                        char time_str[64];
 
-                       if (! sdb_strftime(time_str, sizeof(time_str),
-                                               "%F %T %z", ts->data[i][j].timestamp))
+                       if (! sdb_strftime(time_str, sizeof(time_str), ts->data[i][j].timestamp))
                                snprintf(time_str, sizeof(time_str), "<error>");
                        time_str[sizeof(time_str) - 1] = '\0';
 
index a772dc39c8f67549c8205a0f63527672b6edf473..7362691398af584ed3725d220cbebb85a26d6906 100644 (file)
@@ -140,8 +140,7 @@ json_emit(sdb_store_json_formatter_t *f, sdb_store_obj_t *obj)
        }
 
        /* TODO: make time and interval formats configurable */
-       if (! sdb_strftime(time_str, sizeof(time_str),
-                               "%F %T %z", obj->last_update))
+       if (! sdb_strftime(time_str, sizeof(time_str), obj->last_update))
                snprintf(time_str, sizeof(time_str), "<error>");
        time_str[sizeof(time_str) - 1] = '\0';
 
index d0ed0b8dd9917d11596fa54da2f65071026c968f..d8e8fabf6442e3d83ac02364521c9a1abd54e98e 100644 (file)
@@ -78,18 +78,30 @@ sdb_sleep(sdb_time_t reg, sdb_time_t *rem)
 } /* sdb_sleep */
 
 size_t
-sdb_strftime(char *s, size_t len, const char *format, sdb_time_t t)
+sdb_strftime(char *s, size_t len, sdb_time_t t)
 {
+       char tmp[len];
        time_t tstamp;
        struct tm tm;
+       long tz;
 
        memset(&tm, 0, sizeof(tm));
-
        tstamp = (time_t)SDB_TIME_TO_SECS(t);
        if (! localtime_r (&tstamp, &tm))
                return 0;
 
-       return strftime(s, len, format, &tm);
+       if (! strftime(tmp, len, "%F %T", &tm))
+               return 0;
+       tmp[sizeof(tmp) - 1] = '\0';
+
+       tz = -timezone / 36;
+       if (tm.tm_isdst > 0)
+               tz += 100;
+
+       t %= SDB_INTERVAL_SECOND;
+       if (! t)
+               return snprintf(s, len, "%s %+05ld", tmp, tz);
+       return snprintf(s, len, "%s.%09ld %+05ld", tmp, t, tz);
 } /* sdb_strftime */
 
 size_t
index c48a2e1329b6bb8371507fa382dcf90601591a18..a9ca72f01a2dbfecc34a9251011f1b3afccb0994 100644 (file)
@@ -74,8 +74,7 @@ int
 sdb_sleep(sdb_time_t reg, sdb_time_t *rem);
 
 size_t
-sdb_strftime(char *s, size_t len, const char *format, sdb_time_t)
-               __attribute__((format(strftime, 3, 0)));
+sdb_strftime(char *s, size_t len, sdb_time_t);
 
 size_t
 sdb_strfinterval(char *s, size_t len, sdb_time_t interval);
index dea83d7e0c828d8966fbffe9e91a2895c466fdf7..9bbd9ba7c9fe31c1575a1160f3ffd218c6ba04fa 100644 (file)
@@ -568,8 +568,8 @@ analyze_timeseries(sdb_ast_timeseries_t *ts, sdb_strbuf_t *errbuf)
        }
        if (ts->end <= ts->start) {
                char start_str[64], end_str[64];
-               sdb_strftime(start_str, sizeof(start_str), "%F %T Tz", ts->start);
-               sdb_strftime(end_str, sizeof(end_str), "%F %T Tz", ts->end);
+               sdb_strftime(start_str, sizeof(start_str), ts->start);
+               sdb_strftime(end_str, sizeof(end_str), ts->end);
                sdb_strbuf_sprintf(errbuf, "Start time (%s) greater than "
                                "end time (%s) in STORE command", start_str, end_str);
                return -1;
index d421e64df3dd90136776a9b84925ccccf689ffab..27daaae149a1bf48dbc7b2b9e0a50a87ae4a4dff 100644 (file)
@@ -2350,7 +2350,7 @@ START_TEST(test_format)
                },
                {
                        { SDB_TYPE_DATETIME, { .datetime= 471147114711471100 } },
-                       "\"1984-12-06 02:11:54 +0000\"",
+                       "\"1984-12-06 02:11:54.711471100 +0000\"",
                },
                {
                        { SDB_TYPE_BINARY, { .binary = { 0, NULL } } },
index b69573c45fde0afd0b90ab5db4402f225eb9ac00..113d3a0010d0f5669e53d68aa6dbd2fdad753858 100644 (file)
 #include <check.h>
 #include <stdlib.h>
 
+/* Make SDB_INTERVAL_SECOND a constant initializer. */
+#undef SDB_INTERVAL_SECOND
+#define SDB_INTERVAL_SECOND 1000000000L
+
 static void
 populate(void)
 {
        sdb_data_t datum;
 
-       sdb_store_host("h1", 1);
-       sdb_store_host("h2", 3);
+       sdb_store_host("h1", 1 * SDB_INTERVAL_SECOND);
+       sdb_store_host("h2", 3 * SDB_INTERVAL_SECOND);
 
        datum.type = SDB_TYPE_STRING;
        datum.data.string = "v1";
-       sdb_store_attribute("h1", "k1", &datum, 1);
+       sdb_store_attribute("h1", "k1", &datum, 1 * SDB_INTERVAL_SECOND);
        datum.data.string = "v2";
-       sdb_store_attribute("h1", "k2", &datum, 2);
+       sdb_store_attribute("h1", "k2", &datum, 2 * SDB_INTERVAL_SECOND);
        datum.data.string = "v3";
-       sdb_store_attribute("h1", "k3", &datum, 2);
+       sdb_store_attribute("h1", "k3", &datum, 2 * SDB_INTERVAL_SECOND);
 
        /* make sure that older updates don't overwrite existing values */
        datum.data.string = "fail";
-       sdb_store_attribute("h1", "k2", &datum, 1);
-       sdb_store_attribute("h1", "k3", &datum, 2);
+       sdb_store_attribute("h1", "k2", &datum, 1 * SDB_INTERVAL_SECOND);
+       sdb_store_attribute("h1", "k3", &datum, 2 * SDB_INTERVAL_SECOND);
 
-       sdb_store_metric("h1", "m1", /* store */ NULL, 2);
-       sdb_store_metric("h1", "m2", /* store */ NULL, 1);
-       sdb_store_metric("h2", "m1", /* store */ NULL, 1);
+       sdb_store_metric("h1", "m1", /* store */ NULL, 2 * SDB_INTERVAL_SECOND);
+       sdb_store_metric("h1", "m2", /* store */ NULL, 1 * SDB_INTERVAL_SECOND);
+       sdb_store_metric("h2", "m1", /* store */ NULL, 1 * SDB_INTERVAL_SECOND);
 
-       sdb_store_service("h2", "s1", 1);
-       sdb_store_service("h2", "s2", 2);
+       sdb_store_service("h2", "s1", 1 * SDB_INTERVAL_SECOND);
+       sdb_store_service("h2", "s2", 2 * SDB_INTERVAL_SECOND);
 
        datum.type = SDB_TYPE_INTEGER;
        datum.data.integer = 42;
-       sdb_store_metric_attr("h1", "m1", "k3", &datum, 2);
+       sdb_store_metric_attr("h1", "m1", "k3", &datum, 2 * SDB_INTERVAL_SECOND);
 
        datum.data.integer = 123;
-       sdb_store_service_attr("h2", "s2", "k1", &datum, 2);
+       sdb_store_service_attr("h2", "s2", "k1", &datum, 2 * SDB_INTERVAL_SECOND);
        datum.data.integer = 4711;
-       sdb_store_service_attr("h2", "s2", "k2", &datum, 1);
+       sdb_store_service_attr("h2", "s2", "k2", &datum, 1 * SDB_INTERVAL_SECOND);
 
        /* don't overwrite k1 */
        datum.data.integer = 666;
-       sdb_store_service_attr("h2", "s2", "k1", &datum, 2);
+       sdb_store_service_attr("h2", "s2", "k1", &datum, 2 * SDB_INTERVAL_SECOND);
 } /* populate */
 
 static int
@@ -133,76 +137,76 @@ struct {
        { { NULL, 0, SDB_DATA_INIT },
                SDB_HOST, scan_tojson_full,
                "["
-                       "{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                       "{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:01 +0000\", "
                                "\"update_interval\": \"0s\", \"backends\": [], "
                                "\"attributes\": ["
                                        "{\"name\": \"k1\", \"value\": \"v1\", "
-                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                                               "\"last_update\": \"1970-01-01 00:00:01 +0000\", "
                                                "\"update_interval\": \"0s\", \"backends\": []},"
                                        "{\"name\": \"k2\", \"value\": \"v2\", "
-                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                                               "\"last_update\": \"1970-01-01 00:00:02 +0000\", "
                                                "\"update_interval\": \"0s\", \"backends\": []},"
                                        "{\"name\": \"k3\", \"value\": \"v3\", "
-                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                                               "\"last_update\": \"1970-01-01 00:00:02 +0000\", "
                                                "\"update_interval\": \"0s\", \"backends\": []}"
                                "], "
                                "\"metrics\": ["
                                        "{\"name\": \"m1\", "
                                                "\"timeseries\": false, "
-                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                                               "\"last_update\": \"1970-01-01 00:00:02 +0000\", "
                                                "\"update_interval\": \"0s\", \"backends\": [], "
                                                "\"attributes\": ["
                                                        "{\"name\": \"hostname\", \"value\": \"h1\", "
-                                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                                                               "\"last_update\": \"1970-01-01 00:00:02 +0000\", "
                                                                "\"update_interval\": \"0s\", \"backends\": []},"
                                                        "{\"name\": \"k3\", \"value\": 42, "
-                                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                                                               "\"last_update\": \"1970-01-01 00:00:02 +0000\", "
                                                                "\"update_interval\": \"0s\", \"backends\": []}"
                                                "]},"
                                        "{\"name\": \"m2\", "
                                                "\"timeseries\": false, "
-                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                                               "\"last_update\": \"1970-01-01 00:00:01 +0000\", "
                                                "\"update_interval\": \"0s\", \"backends\": [], "
                                                "\"attributes\": ["
                                                        "{\"name\": \"hostname\", \"value\": \"h1\", "
-                                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                                                               "\"last_update\": \"1970-01-01 00:00:01 +0000\", "
                                                                "\"update_interval\": \"0s\", \"backends\": []}"
                                                "]}"
                                "]},"
-                       "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                       "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:03 +0000\", "
                                "\"update_interval\": \"0s\", \"backends\": [], "
                                "\"metrics\": ["
                                        "{\"name\": \"m1\", "
                                                "\"timeseries\": false, "
-                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                                               "\"last_update\": \"1970-01-01 00:00:01 +0000\", "
                                                "\"update_interval\": \"0s\", \"backends\": [], "
                                                "\"attributes\": ["
                                                        "{\"name\": \"hostname\", \"value\": \"h2\", "
-                                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                                                               "\"last_update\": \"1970-01-01 00:00:01 +0000\", "
                                                                "\"update_interval\": \"0s\", \"backends\": []}"
                                                "]}"
                                "], "
                                "\"services\": ["
                                        "{\"name\": \"s1\", "
-                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                                               "\"last_update\": \"1970-01-01 00:00:01 +0000\", "
                                                "\"update_interval\": \"0s\", \"backends\": [], "
                                                "\"attributes\": ["
                                                        "{\"name\": \"hostname\", \"value\": \"h2\", "
-                                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                                                               "\"last_update\": \"1970-01-01 00:00:01 +0000\", "
                                                                "\"update_interval\": \"0s\", \"backends\": []}"
                                                "]},"
                                        "{\"name\": \"s2\", "
-                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                                               "\"last_update\": \"1970-01-01 00:00:02 +0000\", "
                                                "\"update_interval\": \"0s\", \"backends\": [], "
                                                "\"attributes\": ["
                                                        "{\"name\": \"hostname\", \"value\": \"h2\", "
-                                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                                                               "\"last_update\": \"1970-01-01 00:00:02 +0000\", "
                                                                "\"update_interval\": \"0s\", \"backends\": []},"
                                                        "{\"name\": \"k1\", \"value\": 123, "
-                                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                                                               "\"last_update\": \"1970-01-01 00:00:02 +0000\", "
                                                                "\"update_interval\": \"0s\", \"backends\": []},"
                                                        "{\"name\": \"k2\", \"value\": 4711, "
-                                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                                                               "\"last_update\": \"1970-01-01 00:00:01 +0000\", "
                                                                "\"update_interval\": \"0s\", \"backends\": []}"
                                                "]}"
                                "]}"
@@ -210,66 +214,66 @@ struct {
        { { NULL, 0, SDB_DATA_INIT },
                SDB_HOST, scan_tojson,
                "["
-                       "{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                       "{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:01 +0000\", "
                                "\"update_interval\": \"0s\", \"backends\": []},"
-                       "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                       "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:03 +0000\", "
                                "\"update_interval\": \"0s\", \"backends\": []}"
                "]" },
        { { sdb_store_eq_matcher, SDB_FIELD_NAME,
                        { SDB_TYPE_STRING, { .string = "h1" } } },
                SDB_HOST, scan_tojson_full,
                "["
-                       "{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                       "{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:01 +0000\", "
                                "\"update_interval\": \"0s\", \"backends\": []}"
                "]" },
        { { sdb_store_gt_matcher, SDB_FIELD_LAST_UPDATE,
-                       { SDB_TYPE_DATETIME, { .datetime = 1 } } },
+                       { SDB_TYPE_DATETIME, { .datetime = 1 * SDB_INTERVAL_SECOND } } },
                SDB_HOST, scan_tojson_full,
                "["
-                       "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                       "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:03 +0000\", "
                                "\"update_interval\": \"0s\", \"backends\": [], "
                                "\"services\": ["
                                        "{\"name\": \"s2\", "
-                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                                               "\"last_update\": \"1970-01-01 00:00:02 +0000\", "
                                                "\"update_interval\": \"0s\", \"backends\": [], "
                                                "\"attributes\": ["
                                                        "{\"name\": \"hostname\", \"value\": \"h2\", "
-                                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                                                               "\"last_update\": \"1970-01-01 00:00:02 +0000\", "
                                                                "\"update_interval\": \"0s\", \"backends\": []},"
                                                        "{\"name\": \"k1\", \"value\": 123, "
-                                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                                                               "\"last_update\": \"1970-01-01 00:00:02 +0000\", "
                                                                "\"update_interval\": \"0s\", \"backends\": []}"
                                                "]}"
                                "]}"
                "]" },
        { { sdb_store_le_matcher, SDB_FIELD_LAST_UPDATE,
-                       { SDB_TYPE_DATETIME, { .datetime = 1 } } },
+                       { SDB_TYPE_DATETIME, { .datetime = 1 * SDB_INTERVAL_SECOND } } },
                SDB_HOST, scan_tojson_full,
                "["
-                       "{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                       "{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:01 +0000\", "
                                "\"update_interval\": \"0s\", \"backends\": [], "
                                "\"attributes\": ["
                                        "{\"name\": \"k1\", \"value\": \"v1\", "
-                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                                               "\"last_update\": \"1970-01-01 00:00:01 +0000\", "
                                                "\"update_interval\": \"0s\", \"backends\": []}"
                                "], "
                                "\"metrics\": ["
                                        "{\"name\": \"m2\", "
                                                "\"timeseries\": false, "
-                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                                               "\"last_update\": \"1970-01-01 00:00:01 +0000\", "
                                                "\"update_interval\": \"0s\", \"backends\": [], "
                                                "\"attributes\": ["
                                                        "{\"name\": \"hostname\", \"value\": \"h1\", "
-                                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                                                               "\"last_update\": \"1970-01-01 00:00:01 +0000\", "
                                                                "\"update_interval\": \"0s\", \"backends\": []}"
                                                "]}"
                                "]}"
                "]" },
        { { sdb_store_ge_matcher, SDB_FIELD_LAST_UPDATE,
-                       { SDB_TYPE_DATETIME, { .datetime = 3 } } },
+                       { SDB_TYPE_DATETIME, { .datetime = 3 * SDB_INTERVAL_SECOND } } },
                SDB_HOST, scan_tojson_full,
                "["
-                       "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                       "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:03 +0000\", "
                                "\"update_interval\": \"0s\", \"backends\": []}"
                "]" },
        { { sdb_store_lt_matcher, SDB_FIELD_LAST_UPDATE,
@@ -280,29 +284,29 @@ struct {
        { { NULL, 0, SDB_DATA_INIT },
                SDB_SERVICE, scan_tojson_full,
                "["
-                       "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                       "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:03 +0000\", "
                                "\"update_interval\": \"0s\", \"backends\": [], "
                                "\"services\": ["
                                        "{\"name\": \"s1\", "
-                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                                               "\"last_update\": \"1970-01-01 00:00:01 +0000\", "
                                                "\"update_interval\": \"0s\", \"backends\": [], "
                                                "\"attributes\": ["
                                                        "{\"name\": \"hostname\", \"value\": \"h2\", "
-                                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                                                               "\"last_update\": \"1970-01-01 00:00:01 +0000\", "
                                                                "\"update_interval\": \"0s\", \"backends\": []}"
                                                "]},"
                                        "{\"name\": \"s2\", "
-                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                                               "\"last_update\": \"1970-01-01 00:00:02 +0000\", "
                                                "\"update_interval\": \"0s\", \"backends\": [], "
                                                "\"attributes\": ["
                                                        "{\"name\": \"hostname\", \"value\": \"h2\", "
-                                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                                                               "\"last_update\": \"1970-01-01 00:00:02 +0000\", "
                                                                "\"update_interval\": \"0s\", \"backends\": []},"
                                                        "{\"name\": \"k1\", \"value\": 123, "
-                                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                                                               "\"last_update\": \"1970-01-01 00:00:02 +0000\", "
                                                                "\"update_interval\": \"0s\", \"backends\": []},"
                                                        "{\"name\": \"k2\", \"value\": 4711, "
-                                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                                                               "\"last_update\": \"1970-01-01 00:00:01 +0000\", "
                                                                "\"update_interval\": \"0s\", \"backends\": []}"
                                                "]}"
                                "]}"
@@ -310,33 +314,33 @@ struct {
        { { NULL, 0, SDB_DATA_INIT },
                SDB_SERVICE, scan_tojson,
                "["
-                       "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                       "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:03 +0000\", "
                                "\"update_interval\": \"0s\", \"backends\": [], "
                                "\"services\": ["
                                        "{\"name\": \"s1\", "
-                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                                               "\"last_update\": \"1970-01-01 00:00:01 +0000\", "
                                                "\"update_interval\": \"0s\", \"backends\": []},"
                                        "{\"name\": \"s2\", "
-                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                                               "\"last_update\": \"1970-01-01 00:00:02 +0000\", "
                                                "\"update_interval\": \"0s\", \"backends\": []}"
                                "]}"
                "]" },
        { { sdb_store_gt_matcher, SDB_FIELD_LAST_UPDATE,
-                       { SDB_TYPE_DATETIME, { .datetime = 1 } } },
+                       { SDB_TYPE_DATETIME, { .datetime = 1 * SDB_INTERVAL_SECOND } } },
                SDB_SERVICE, scan_tojson_full,
                "["
-                       "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                       "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:03 +0000\", "
                                "\"update_interval\": \"0s\", \"backends\": [], "
                                "\"services\": ["
                                        "{\"name\": \"s2\", "
-                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                                               "\"last_update\": \"1970-01-01 00:00:02 +0000\", "
                                                "\"update_interval\": \"0s\", \"backends\": [], "
                                                "\"attributes\": ["
                                                        "{\"name\": \"hostname\", \"value\": \"h2\", "
-                                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                                                               "\"last_update\": \"1970-01-01 00:00:02 +0000\", "
                                                                "\"update_interval\": \"0s\", \"backends\": []},"
                                                        "{\"name\": \"k1\", \"value\": 123, "
-                                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                                                               "\"last_update\": \"1970-01-01 00:00:02 +0000\", "
                                                                "\"update_interval\": \"0s\", \"backends\": []}"
                                                "]}"
                                "]}"
@@ -348,41 +352,41 @@ struct {
        { { NULL, 0, SDB_DATA_INIT },
                SDB_METRIC, scan_tojson_full,
                "["
-                       "{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                       "{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:01 +0000\", "
                                "\"update_interval\": \"0s\", \"backends\": [], "
                                "\"metrics\": ["
                                        "{\"name\": \"m1\", "
                                                "\"timeseries\": false, "
-                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                                               "\"last_update\": \"1970-01-01 00:00:02 +0000\", "
                                                "\"update_interval\": \"0s\", \"backends\": [], "
                                                "\"attributes\": ["
                                                        "{\"name\": \"hostname\", \"value\": \"h1\", "
-                                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                                                               "\"last_update\": \"1970-01-01 00:00:02 +0000\", "
                                                                "\"update_interval\": \"0s\", \"backends\": []},"
                                                        "{\"name\": \"k3\", \"value\": 42, "
-                                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                                                               "\"last_update\": \"1970-01-01 00:00:02 +0000\", "
                                                                "\"update_interval\": \"0s\", \"backends\": []}"
                                                "]},"
                                        "{\"name\": \"m2\", "
                                                "\"timeseries\": false, "
-                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                                               "\"last_update\": \"1970-01-01 00:00:01 +0000\", "
                                                "\"update_interval\": \"0s\", \"backends\": [], "
                                                "\"attributes\": ["
                                                        "{\"name\": \"hostname\", \"value\": \"h1\", "
-                                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                                                               "\"last_update\": \"1970-01-01 00:00:01 +0000\", "
                                                                "\"update_interval\": \"0s\", \"backends\": []}"
                                                "]}"
                                "]},"
-                       "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                       "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:03 +0000\", "
                                "\"update_interval\": \"0s\", \"backends\": [], "
                                "\"metrics\": ["
                                        "{\"name\": \"m1\", "
                                                "\"timeseries\": false, "
-                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                                               "\"last_update\": \"1970-01-01 00:00:01 +0000\", "
                                                "\"update_interval\": \"0s\", \"backends\": [], "
                                                "\"attributes\": ["
                                                        "{\"name\": \"hostname\", \"value\": \"h2\", "
-                                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                                                               "\"last_update\": \"1970-01-01 00:00:01 +0000\", "
                                                                "\"update_interval\": \"0s\", \"backends\": []}"
                                                "]}"
                                "]}"
@@ -390,41 +394,41 @@ struct {
        { { NULL, 0, SDB_DATA_INIT },
                SDB_METRIC, scan_tojson,
                "["
-                       "{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                       "{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:01 +0000\", "
                                "\"update_interval\": \"0s\", \"backends\": [], "
                                "\"metrics\": ["
                                        "{\"name\": \"m1\", "
                                                "\"timeseries\": false, "
-                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                                               "\"last_update\": \"1970-01-01 00:00:02 +0000\", "
                                                "\"update_interval\": \"0s\", \"backends\": []},"
                                        "{\"name\": \"m2\", "
                                                "\"timeseries\": false, "
-                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                                               "\"last_update\": \"1970-01-01 00:00:01 +0000\", "
                                                "\"update_interval\": \"0s\", \"backends\": []}"
                                "]},"
-                       "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                       "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:03 +0000\", "
                                "\"update_interval\": \"0s\", \"backends\": [], "
                                "\"metrics\": ["
                                        "{\"name\": \"m1\", "
                                                "\"timeseries\": false, "
-                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                                               "\"last_update\": \"1970-01-01 00:00:01 +0000\", "
                                                "\"update_interval\": \"0s\", \"backends\": []}"
                                "]}"
                "]" },
        { { sdb_store_le_matcher, SDB_FIELD_LAST_UPDATE,
-                       { SDB_TYPE_DATETIME, { .datetime = 1 } } },
+                       { SDB_TYPE_DATETIME, { .datetime = 1 * SDB_INTERVAL_SECOND } } },
                SDB_METRIC, scan_tojson_full,
                "["
-                       "{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                       "{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:01 +0000\", "
                                "\"update_interval\": \"0s\", \"backends\": [], "
                                "\"metrics\": ["
                                        "{\"name\": \"m2\", "
                                                "\"timeseries\": false, "
-                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                                               "\"last_update\": \"1970-01-01 00:00:01 +0000\", "
                                                "\"update_interval\": \"0s\", \"backends\": [], "
                                                "\"attributes\": ["
                                                        "{\"name\": \"hostname\", \"value\": \"h1\", "
-                                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", "
+                                                               "\"last_update\": \"1970-01-01 00:00:01 +0000\", "
                                                                "\"update_interval\": \"0s\", \"backends\": []}"
                                                "]}"
                                "]}"
index 9fee9dbd46303987b02b3a814010f80d59612296..978fc02d6f99eb47636391e975520489f3fbfe9b 100644 (file)
 #define US                                     1000L
 #define NS                                        1L
 
+struct {
+       sdb_time_t t;
+       const char *tz;
+       const char *expected;
+} strftime_data[] = {
+       { 0,                    "UTC",           "1970-01-01 00:00:00 +0000" },
+       { 1428066243000000000L, "Europe/Berlin", "2015-04-03 15:04:03 +0200" },
+       { 1420113661000000000L, "Europe/Berlin", "2015-01-01 13:01:01 +0100" },
+       { 1428066243000000000L, "US/Pacific",    "2015-04-03 06:04:03 -0700" },
+       { 1420113661000000000L, "US/Pacific",    "2015-01-01 04:01:01 -0800" },
+       { 1146747723000000123L, "UTC", "2006-05-04 13:02:03.000000123 +0000" },
+       { 1146747723123456789L, "UTC", "2006-05-04 13:02:03.123456789 +0000" },
+};
+
+START_TEST(test_strftime)
+{
+       char buf[1024], tz[64];
+       size_t check;
+
+       /* strftime does not provide the number of bytes that would have been
+        * written. Only check that it does not segfault. */
+       sdb_strftime(NULL, 0, strftime_data[_i].t);
+
+       snprintf(tz, sizeof(tz), "TZ=%s", strftime_data[_i].tz);
+       putenv(tz);
+       tzset();
+
+       check = sdb_strftime(buf, sizeof(buf), strftime_data[_i].t);
+       fail_unless(check > 0,
+                       "%s; sdb_strftime(<buf>, <size>, %"PRIsdbTIME") = %zu; "
+                       "expected: >0", tz, strftime_data[_i].t, check);
+       fail_unless(!strcmp(buf, strftime_data[_i].expected),
+                       "%s; sdb_strftime(<buf>, <size>, %"PRIsdbTIME") did not "
+                       "format time correctly; got: '%s'; expected: '%s'",
+                       tz, strftime_data[_i].t, buf, strftime_data[_i].expected);
+       fail_unless(check == strlen(strftime_data[_i].expected),
+                       "%s; sdb_strftime(<buf>, <size>, %"PRIsdbTIME") = %zu; "
+                       "expected: %zu", tz, strftime_data[_i].t, check,
+                       strlen(strftime_data[_i].expected));
+
+       putenv("TZ=UTC");
+       tzset();
+}
+END_TEST
+
 struct {
        sdb_time_t  interval;
        const char *expected;
@@ -130,6 +175,7 @@ END_TEST
 TEST_MAIN("core::time")
 {
        TCase *tc = tcase_create("core");
+       TC_ADD_LOOP_TEST(tc, strftime);
        TC_ADD_LOOP_TEST(tc, strfinterval);
        TC_ADD_LOOP_TEST(tc, strpunit);
        ADD_TCASE(tc);
index 861313f5363d9094897b83f967f5782f9ae772f2..8872e5b6e13a0f2879430e20e65f7c7f1bf27ebf 100644 (file)
@@ -44,134 +44,134 @@ populate(void)
 {
        sdb_data_t datum;
 
-       sdb_store_host("h1", 1);
-       sdb_store_host("h2", 3);
+       sdb_store_host("h1", 1 * SDB_INTERVAL_SECOND);
+       sdb_store_host("h2", 3 * SDB_INTERVAL_SECOND);
 
        datum.type = SDB_TYPE_STRING;
        datum.data.string = "v1";
-       sdb_store_attribute("h1", "k1", &datum, 1);
+       sdb_store_attribute("h1", "k1", &datum, 1 * SDB_INTERVAL_SECOND);
        datum.data.string = "v2";
-       sdb_store_attribute("h1", "k2", &datum, 2);
+       sdb_store_attribute("h1", "k2", &datum, 2 * SDB_INTERVAL_SECOND);
        datum.data.string = "v3";
-       sdb_store_attribute("h1", "k3", &datum, 2);
+       sdb_store_attribute("h1", "k3", &datum, 2 * SDB_INTERVAL_SECOND);
 
-       sdb_store_metric("h1", "m1", /* store */ NULL, 2);
-       sdb_store_metric("h1", "m2", /* store */ NULL, 1);
-       sdb_store_metric("h2", "m1", /* store */ NULL, 1);
+       sdb_store_metric("h1", "m1", /* store */ NULL, 2 * SDB_INTERVAL_SECOND);
+       sdb_store_metric("h1", "m2", /* store */ NULL, 1 * SDB_INTERVAL_SECOND);
+       sdb_store_metric("h2", "m1", /* store */ NULL, 1 * SDB_INTERVAL_SECOND);
 
        datum.type = SDB_TYPE_INTEGER;
        datum.data.integer = 42;
-       sdb_store_metric_attr("h1", "m1", "k3", &datum, 2);
+       sdb_store_metric_attr("h1", "m1", "k3", &datum, 2 * SDB_INTERVAL_SECOND);
 
-       sdb_store_service("h2", "s1", 1);
-       sdb_store_service("h2", "s2", 2);
+       sdb_store_service("h2", "s1", 1 * SDB_INTERVAL_SECOND);
+       sdb_store_service("h2", "s2", 2 * SDB_INTERVAL_SECOND);
 
        datum.data.integer = 123;
-       sdb_store_service_attr("h2", "s2", "k1", &datum, 2);
+       sdb_store_service_attr("h2", "s2", "k1", &datum, 2 * SDB_INTERVAL_SECOND);
        datum.data.integer = 4711;
-       sdb_store_service_attr("h2", "s2", "k2", &datum, 1);
+       sdb_store_service_attr("h2", "s2", "k2", &datum, 1 * SDB_INTERVAL_SECOND);
 } /* populate */
 
 #define HOST_H1 \
-       "{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:00 +0000\", " \
+       "{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:01 +0000\", " \
                        "\"update_interval\": \"0s\", \"backends\": [], " \
                "\"attributes\": [" \
                        "{\"name\": \"k1\", \"value\": \"v1\", " \
-                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", " \
+                               "\"last_update\": \"1970-01-01 00:00:01 +0000\", " \
                                "\"update_interval\": \"0s\", \"backends\": []}," \
                        "{\"name\": \"k2\", \"value\": \"v2\", " \
-                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", " \
+                               "\"last_update\": \"1970-01-01 00:00:02 +0000\", " \
                                "\"update_interval\": \"0s\", \"backends\": []}," \
                        "{\"name\": \"k3\", \"value\": \"v3\", " \
-                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", " \
+                               "\"last_update\": \"1970-01-01 00:00:02 +0000\", " \
                                "\"update_interval\": \"0s\", \"backends\": []}], " \
                "\"metrics\": [" \
                        "{\"name\": \"m1\", \"timeseries\": false, " \
-                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", " \
+                               "\"last_update\": \"1970-01-01 00:00:02 +0000\", " \
                                "\"update_interval\": \"0s\", \"backends\": [], " \
                                "\"attributes\": [" \
                                        "{\"name\": \"hostname\", \"value\": \"h1\", " \
-                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", " \
+                                               "\"last_update\": \"1970-01-01 00:00:02 +0000\", " \
                                                "\"update_interval\": \"0s\", \"backends\": []}," \
                                        "{\"name\": \"k3\", \"value\": 42, " \
-                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", " \
+                                               "\"last_update\": \"1970-01-01 00:00:02 +0000\", " \
                                                "\"update_interval\": \"0s\", \"backends\": []}]}," \
                        "{\"name\": \"m2\", \"timeseries\": false, " \
-                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", " \
+                               "\"last_update\": \"1970-01-01 00:00:01 +0000\", " \
                                "\"update_interval\": \"0s\", \"backends\": [], " \
                                "\"attributes\": [" \
                                        "{\"name\": \"hostname\", \"value\": \"h1\", " \
-                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", " \
+                                               "\"last_update\": \"1970-01-01 00:00:01 +0000\", " \
                                                "\"update_interval\": \"0s\", \"backends\": []}]}]}"
 #define HOST_H1_ARRAY "["HOST_H1"]"
 #define HOST_H1_LISTING \
-       "{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:00 +0000\", " \
+       "{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:01 +0000\", " \
                        "\"update_interval\": \"0s\", \"backends\": []}"
 #define HOST_H2_LISTING \
-       "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:00 +0000\", " \
+       "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:03 +0000\", " \
                        "\"update_interval\": \"0s\", \"backends\": []}"
 
 #define SERVICE_H2_S1 \
-       "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:00 +0000\", " \
+       "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:03 +0000\", " \
                        "\"update_interval\": \"0s\", \"backends\": [], " \
                "\"services\": [" \
-                       "{\"name\": \"s1\", \"last_update\": \"1970-01-01 00:00:00 +0000\", " \
+                       "{\"name\": \"s1\", \"last_update\": \"1970-01-01 00:00:01 +0000\", " \
                                "\"update_interval\": \"0s\", \"backends\": [], " \
                                "\"attributes\": [" \
                                        "{\"name\": \"hostname\", \"value\": \"h2\", " \
-                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", " \
+                                               "\"last_update\": \"1970-01-01 00:00:01 +0000\", " \
                                                "\"update_interval\": \"0s\", \"backends\": []}]}]}"
 #define SERVICE_H2_S1_ARRAY "["SERVICE_H2_S1"]"
 #define SERVICE_H2_S12_LISTING \
-       "[{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:00 +0000\", " \
+       "[{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:03 +0000\", " \
                        "\"update_interval\": \"0s\", \"backends\": [], " \
                "\"services\": [" \
-                       "{\"name\": \"s1\", \"last_update\": \"1970-01-01 00:00:00 +0000\", " \
+                       "{\"name\": \"s1\", \"last_update\": \"1970-01-01 00:00:01 +0000\", " \
                                "\"update_interval\": \"0s\", \"backends\": []}," \
-                       "{\"name\": \"s2\", \"last_update\": \"1970-01-01 00:00:00 +0000\", " \
+                       "{\"name\": \"s2\", \"last_update\": \"1970-01-01 00:00:02 +0000\", " \
                                "\"update_interval\": \"0s\", \"backends\": []}]}]"
 
 #define METRIC_H1_M1 \
-       "{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:00 +0000\", " \
+       "{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:01 +0000\", " \
                        "\"update_interval\": \"0s\", \"backends\": [], " \
                "\"metrics\": [" \
                        "{\"name\": \"m1\", \"timeseries\": false, " \
-                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", " \
+                               "\"last_update\": \"1970-01-01 00:00:02 +0000\", " \
                                "\"update_interval\": \"0s\", \"backends\": [], " \
                                "\"attributes\": [" \
                                        "{\"name\": \"hostname\", \"value\": \"h1\", " \
-                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", " \
+                                               "\"last_update\": \"1970-01-01 00:00:02 +0000\", " \
                                                "\"update_interval\": \"0s\", \"backends\": []}," \
                                        "{\"name\": \"k3\", \"value\": 42, " \
-                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", " \
+                                               "\"last_update\": \"1970-01-01 00:00:02 +0000\", " \
                                                "\"update_interval\": \"0s\", \"backends\": []}]}]}"
 #define METRIC_H12_M1_ARRAY \
        "["METRIC_H1_M1"," \
-       "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:00 +0000\", " \
+       "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:03 +0000\", " \
                        "\"update_interval\": \"0s\", \"backends\": [], " \
                "\"metrics\": [" \
                        "{\"name\": \"m1\", \"timeseries\": false, " \
-                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", " \
+                               "\"last_update\": \"1970-01-01 00:00:01 +0000\", " \
                                "\"update_interval\": \"0s\", \"backends\": [], " \
                                "\"attributes\": [" \
                                        "{\"name\": \"hostname\", \"value\": \"h2\", " \
-                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", " \
+                                               "\"last_update\": \"1970-01-01 00:00:01 +0000\", " \
                                                "\"update_interval\": \"0s\", \"backends\": []}]}]}]"
 #define METRIC_H12_M12_LISTING \
-       "[{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:00 +0000\", " \
+       "[{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:01 +0000\", " \
                        "\"update_interval\": \"0s\", \"backends\": [], " \
                "\"metrics\": [" \
                        "{\"name\": \"m1\", \"timeseries\": false, " \
-                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", " \
+                               "\"last_update\": \"1970-01-01 00:00:02 +0000\", " \
                                "\"update_interval\": \"0s\", \"backends\": []}," \
                        "{\"name\": \"m2\", \"timeseries\": false, " \
-                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", " \
+                               "\"last_update\": \"1970-01-01 00:00:01 +0000\", " \
                                "\"update_interval\": \"0s\", \"backends\": []}]}," \
-       "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:00 +0000\", " \
+       "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:03 +0000\", " \
                        "\"update_interval\": \"0s\", \"backends\": [], " \
                "\"metrics\": [" \
                        "{\"name\": \"m1\", \"timeseries\": false, " \
-                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", " \
+                               "\"last_update\": \"1970-01-01 00:00:01 +0000\", " \
                                "\"update_interval\": \"0s\", \"backends\": []}]}]"
 
 typedef struct {
index a6989655e1c5d481426cab9ed83e750bf31bc8f6..5e0cc853d101b06c9aca1268665cc5807517d44b 100644 (file)
@@ -37,6 +37,7 @@
 #include <check.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <time.h>
 
 #define TEST_MAIN(name) \
        int main(void) \
@@ -45,6 +46,7 @@
                Suite *s; \
                int failed; \
                putenv("TZ=UTC"); \
+               tzset(); \
                s = suite_create(name); \
                sr = srunner_create(s); \