From eb8dbc0d4cddd1161e2b02d7973985a36e2efc95 Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Fri, 18 Mar 2022 20:31:27 -0400 Subject: datetime: Get now (struct tm) from caller --- (limited to 'src/datetime.c') diff --git a/src/datetime.c b/src/datetime.c index 59adcb9..27c27a2 100644 --- a/src/datetime.c +++ b/src/datetime.c @@ -117,14 +117,9 @@ _datetime_reset_tm(struct tm *tm) } static void -_datetime_normalize(struct tm *arg_tm, time_t *arg_sec) +_datetime_normalize(struct tm *now_tm, struct tm *arg_tm, time_t *arg_sec) { - time_t now_sec; - struct tm *now_tm; - int wday; - - now_sec = time(NULL); - now_tm = localtime(&now_sec); + int wday; if (arg_tm->tm_sec == INT_MIN) { arg_tm->tm_sec = 0; @@ -177,7 +172,7 @@ _datetime_normalize(struct tm *arg_tm, time_t *arg_sec) } int -datetime_parse(const char *input, time_t *arg_sec) +datetime_parse(struct tm *now_tm, const char *input, time_t *arg_sec) { int date_fmt_len; int time_fmt_len; @@ -207,7 +202,7 @@ datetime_parse(const char *input, time_t *arg_sec) end = strptime(input, fmt_buf, &arg_tm); if (end != NULL && *end == '\0') { free(fmt_buf); - _datetime_normalize(&arg_tm, arg_sec); + _datetime_normalize(now_tm, &arg_tm, arg_sec); return 0; } } @@ -223,7 +218,7 @@ datetime_parse(const char *input, time_t *arg_sec) end = strptime(input, fmt_buf, &arg_tm); if (end != NULL && *end == '\0') { free(fmt_buf); - _datetime_normalize(&arg_tm, arg_sec); + _datetime_normalize(now_tm, &arg_tm, arg_sec); return 0; } } @@ -234,7 +229,7 @@ datetime_parse(const char *input, time_t *arg_sec) end = strptime(input, DATETIME_MISC_FMTS_[d], &arg_tm); if (end != NULL && *end == '\0') { free(fmt_buf); - _datetime_normalize(&arg_tm, arg_sec); + _datetime_normalize(now_tm, &arg_tm, arg_sec); return 0; } } -- cgit v0.9.1