From 9cd440f305850b5a26fd18931fcc4637a383acf7 Mon Sep 17 00:00:00 2001 From: nekobit Date: Tue, 24 May 2022 06:20:01 +0000 Subject: [PATCH] Local timestamp FossilOrigin-Name: 7dfeca0708f2945df858d34d3192024fe73f1e1832074f151e236431e8b7ea9d --- src/json_helper.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/json_helper.c b/src/json_helper.c index c27103e..46a95f4 100644 --- a/src/json_helper.c +++ b/src/json_helper.c @@ -13,6 +13,8 @@ * along with this program. If not, see . */ +#define _XOPEN_SOURCE +#define _DEFAULT_SOURCE #include #include #include @@ -66,18 +68,26 @@ void _mstdnt_val_string_unix_call(cJSON* v, void* _type) void _mstdnt_val_datetime_unix_call(cJSON* v, void* _type) { - struct tm conv_time = { 0 }; + // First, assure correct time properties like DST + time_t loc_time = time(NULL); + struct tm* conv_time_cpy = gmtime(&loc_time); + struct tm conv_time; + // Copy over for use + memcpy(&conv_time, conv_time_cpy, sizeof(struct tm)); + time_t* type = _type; if (sscanf(v->valuestring, "%d-%d-%dT%d:%d:%d.000Z", - &conv_time.tm_year - 1900, + &conv_time.tm_year, &conv_time.tm_mon, &conv_time.tm_mday, &conv_time.tm_hour, &conv_time.tm_min, &conv_time.tm_sec) == 6) { - *type = mktime(&conv_time); + conv_time.tm_year -= 1900; + conv_time.tm_mon -= 1; + *type = mktime(&conv_time) - timezone; } else *type = 0; // 70's, baby!