diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2021-09-30 07:14:00 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2021-09-30 07:14:00 +0300 |
commit | 305b124c78459fe1d89a6ed4ebf30a955d530a4c (patch) | |
tree | 01366b6e0ff3c880f33461e1e1c7f506defd092e | |
parent | fb34abc341b1508c5f8b91bb7114a5e8ebd957bb (diff) | |
download | mailutils-305b124c78459fe1d89a6ed4ebf30a955d530a4c.tar.gz mailutils-305b124c78459fe1d89a6ed4ebf30a955d530a4c.tar.bz2 |
Fix timezone calculation (see https://savannah.gnu.org/bugs/?61239)
* libmailutils/datetime/utcoff.c (mu_utc_offset): Fix the timezone
correction.
-rw-r--r-- | libmailutils/datetime/utcoff.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/libmailutils/datetime/utcoff.c b/libmailutils/datetime/utcoff.c index 6d448c22a..98d238ef7 100644 --- a/libmailutils/datetime/utcoff.c +++ b/libmailutils/datetime/utcoff.c @@ -19,6 +19,7 @@ #endif #include <time.h> +#define SECS_PER_DAY 86400 #define TMSEC(t) (((t)->tm_hour * 60 + (t)->tm_min) * 60 + (t)->tm_sec) /* Returns the offset of our timezone from UTC, in seconds. */ @@ -29,9 +30,9 @@ mu_utc_offset (void) struct tm ltm = *localtime (&t); struct tm gtm = *gmtime (&t); int d = TMSEC (<m) - TMSEC (>m); - if (!(ltm.tm_year == gtm.tm_year - && ltm.tm_mon == gtm.tm_mon - && ltm.tm_mday == gtm.tm_mday)) - d += 86400; + if (d < 0 && -d > SECS_PER_DAY/2) + d += SECS_PER_DAY; + else if (d > SECS_PER_DAY/2) + d -= SECS_PER_DAY; return d; } |