Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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
  • Loading branch information
metaron-uk authored and perexg committed Sep 22, 2015
1 parent 2969c94 commit 987dc11
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
11 changes: 11 additions & 0 deletions configure
Expand Up @@ -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>
Expand Down
22 changes: 21 additions & 1 deletion src/htsp_server.c
Expand Up @@ -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;
}

Expand Down

0 comments on commit 987dc11

Please sign in to comment.