From 69762b6a9dc6bcd47257134b3e357e6f55a1d658 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Tue, 18 Feb 2025 23:37:17 +0100 Subject: [PATCH] lib/strtoday.c: Actually return a date from get_date() Signed-off-by: Alejandro Colomar --- lib/strtoday.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/lib/strtoday.c b/lib/strtoday.c index ea327faee..ac3be8000 100644 --- a/lib/strtoday.c +++ b/lib/strtoday.c @@ -18,7 +18,8 @@ #include "string/strcmp/streq.h" -static time_t get_date(const char *s); +static long get_date(const char *s); +static long dategm(struct tm *tm); // string parse-to day-since-Epoch @@ -26,7 +27,6 @@ long strtoday(const char *str) { long d; - time_t t; if (NULL == str || streq(str, "")) return -1; @@ -37,15 +37,15 @@ strtoday(const char *str) if (str2sl(&d, str) == 0) return d; - t = get_date(str); - if ((time_t) - 1 == t) { + d = get_date(str); + if (d == -1) return -2; - } - return t / DAY; + + return d; } -static time_t +static long get_date(const char *s) { time_t t; @@ -60,5 +60,18 @@ get_date(const char *s) if (p == NULL || !streq(p, "")) return -1; - return timegm(&tm); + return dategm(&tm); +} + + +static long +dategm(struct tm *tm) +{ + time_t t; + + t = timegm(tm); + if (t == (time_t) -1) + return -1; + + return t / DAY; } -- 2.47.2