diff options
author | Lukas Fleischer <lfleischer@calcurse.org> | 2016-03-27 12:54:10 +0200 |
---|---|---|
committer | Lukas Fleischer <lfleischer@calcurse.org> | 2016-03-27 13:06:18 +0200 |
commit | 9e160fac16e81c42ac368f450b9cc4df29753e00 (patch) | |
tree | 9fe79f9b549f840b0d93cdfd79554e32f8e62dc1 /src/utils.c | |
parent | e1b6d226692ddaa8a9f077796a23317d36cd5d10 (diff) | |
download | calcurse-9e160fac16e81c42ac368f450b9cc4df29753e00.zip |
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>
Diffstat (limited to 'src/utils.c')
-rw-r--r-- | src/utils.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/utils.c b/src/utils.c index 4300b59..50f2507 100644 --- a/src/utils.c +++ b/src/utils.c @@ -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, <1); + localtime_r((time_t *)&d2, <2); + + 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) { |