summaryrefslogtreecommitdiff
path: root/src/base
diff options
context:
space:
mode:
Diffstat (limited to 'src/base')
-rw-r--r--src/base/time.cc29
1 files changed, 27 insertions, 2 deletions
diff --git a/src/base/time.cc b/src/base/time.cc
index c265c1c47..a0ae9bb82 100644
--- a/src/base/time.cc
+++ b/src/base/time.cc
@@ -150,7 +150,32 @@ sleep(const Time &time)
time_t
mkutctime(struct tm *time)
{
- time_t local = mktime(time);
- return mktime(gmtime(&local));
+ // get the current timezone
+ char *tz = getenv("TZ");
+
+ // copy the string as the pointer gets invalidated when updating
+ // the environment
+ if (tz) {
+ tz = strdup(tz);
+ if (!tz) {
+ fatal("Failed to reserve memory for UTC time conversion\n");
+ }
+ }
+
+ // change to UTC and get the time
+ setenv("TZ", "", 1);
+ tzset();
+ time_t ret = mktime(time);
+
+ // restore the timezone again
+ if (tz) {
+ setenv("TZ", tz, 1);
+ free(tz);
+ } else {
+ unsetenv("TZ");
+ }
+ tzset();
+
+ return ret;
}