Skip to content

Commit

Permalink
lib/strtoday.c: Actually return a date from get_date()
Browse files Browse the repository at this point in the history
Signed-off-by: Alejandro Colomar <[email protected]>
  • Loading branch information
alejandro-colomar committed Feb 18, 2025
1 parent d9bc065 commit d6146f0
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions lib/strtoday.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
#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);


long
strtoday(const char *str)
{
long d;
time_t t;
long d;

if (NULL == str)
return -1;
Expand All @@ -36,15 +36,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);
{
struct tm tm;
Expand All @@ -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;
}

0 comments on commit d6146f0

Please sign in to comment.