Do not assume that days always have 86400 seconds

Make that date membership is computed correctly, even if a day has less
than 86400 seconds (e.g. after changing clocks).

Reported-by: Hakan Jerning <jerning@home.se>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
This commit is contained in:
Lukas Fleischer
2016-03-27 12:54:10 +02:00
parent e1b6d22669
commit 9e160fac16
8 changed files with 47 additions and 5 deletions

View File

@@ -418,6 +418,30 @@ time_t utcdate2sec(struct date day, unsigned hour, unsigned min)
return t;
}
/* Compare two dates (without comparing times). */
int date_cmp_day(time_t d1, time_t d2)
{
struct tm lt1, lt2;
localtime_r((time_t *)&d1, &lt1);
localtime_r((time_t *)&d2, &lt2);
if (lt1.tm_year < lt2.tm_year)
return -1;
if (lt1.tm_year > lt2.tm_year)
return 1;
if (lt1.tm_mon < lt2.tm_mon)
return -1;
if (lt1.tm_mon > lt2.tm_mon)
return 1;
if (lt1.tm_mday < lt2.tm_mday)
return -1;
if (lt1.tm_mday > lt2.tm_mday)
return 1;
return 0;
}
/* Return a string containing the date, given a date in seconds. */
char *date_sec2date_str(long sec, const char *datefmt)
{