summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2021-09-30 07:14:00 +0300
committerSergey Poznyakoff <gray@gnu.org>2021-09-30 07:14:00 +0300
commit305b124c78459fe1d89a6ed4ebf30a955d530a4c (patch)
tree01366b6e0ff3c880f33461e1e1c7f506defd092e
parentfb34abc341b1508c5f8b91bb7114a5e8ebd957bb (diff)
downloadmailutils-master.tar.gz
mailutils-master.tar.bz2
Fix timezone calculation (see https://savannah.gnu.org/bugs/?61239)HEADmaster
* libmailutils/datetime/utcoff.c (mu_utc_offset): Fix the timezone correction.
-rw-r--r--libmailutils/datetime/utcoff.c9
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 (&ltm) - TMSEC (&gtm);
- 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;
}

Return to:

Send suggestions and report system problems to the System administrator.