From: metaron Date: Thu, 6 Aug 2015 15:18:11 +0000 (+0100) Subject: Fix GetSysTime "timezone" offset during DST X-Git-Tag: v4.2.1~2072 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=987dc11d0acbaef5674c955216f02efef768b5ee;p=thirdparty%2Ftvheadend.git Fix GetSysTime "timezone" offset during DST This was broken on vanilla glibc systems (don't include DST) Also adds new gmtoffset parameter providing minutes west of GMT --- diff --git a/configure b/configure index d2c09a436..e9def8447 100755 --- a/configure +++ b/configure @@ -185,6 +185,17 @@ int test(void) } ' +check_cc_snippet gmtoff ' +#include +#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 diff --git a/src/htsp_server.c b/src/htsp_server.c index fd25b5f2b..d83d57e60 100644 --- a/src/htsp_server.c +++ b/src/htsp_server.c @@ -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; }