]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
Fix GetSysTime "timezone" offset during DST
authormetaron <andrew@thomasinfletcher.com>
Thu, 6 Aug 2015 15:18:11 +0000 (16:18 +0100)
committerJaroslav Kysela <perex@perex.cz>
Tue, 22 Sep 2015 16:06:32 +0000 (18:06 +0200)
This was broken on vanilla glibc systems (don't include DST)
Also adds new gmtoffset parameter providing minutes west of GMT

configure
src/htsp_server.c

index d2c09a4362b11b9f51bd60b0498e5413a418ed02..e9def8447770beaa1203535d74d1f7599144ba3f 100755 (executable)
--- a/configure
+++ b/configure
@@ -185,6 +185,17 @@ int test(void)
 }
 '
 
+check_cc_snippet gmtoff '
+#include <time.h>
+#define TEST test
+int test(void)
+{
+  struct tm x;
+  x.tm_gmtoff = 0;
+  return 0;
+}
+' -DHAS_GMTOFF
+
 check_cc_snippet recvmmsg '
 #define _GNU_SOURCE
 #include <stdlib.h>
index fd25b5f2b312a761fac30e1cabd0c1882ce8ed0f..d83d57e608219357166f32fb3eabfb2e06023ce1 100644 (file)
@@ -1088,13 +1088,33 @@ htsp_method_getSysTime(htsp_connection_t *htsp, htsmsg_t *in)
   htsmsg_t *out;
   struct timeval tv;
   struct timezone tz;
+  int tz_offset;
+  struct tm serverLocalTime;
 
   if(gettimeofday(&tv, &tz) == -1)
     return htsp_error("Unable to get system time"); 
 
+  if (!localtime_r(&tv.tv_sec, &serverLocalTime))
+    return htsp_error("Unable to get system local time");
+#if defined(HAS_GMTOFF)
+  tz_offset = - serverLocalTime.tm_gmtoff / (60);
+#else
+  // NB: This will be a day out when GMT offsets >= 13hrs or <11 hrs apply
+  struct tm serverGmTime;
+  if (!gmtime_r(&tv.tv_sec, &serverGmTime))
+    return htsp_error("Unable to get system gmt");
+  tz_offset = (serverGmTime.tm_hour - serverLocalTime.tm_hour) * 60;
+  tz_offset += serverGmTime.tm_min - serverLocalTime.tm_min;
+  if (tz_offset > 11 * 60)
+    tz_offset -= 24 * 60;
+  if (tz_offset <= -13 * 60)
+    tz_offset += 24 * 60;
+#endif
+
   out = htsmsg_create_map();
   htsmsg_add_s32(out, "time", tv.tv_sec);
-  htsmsg_add_s32(out, "timezone", tz.tz_minuteswest / 60);
+  htsmsg_add_s32(out, "timezone", tz_offset/60);
+  htsmsg_add_s32(out, "gmtoffset", -tz_offset);
   return out;
 }