From e5bbbababa65da38b2b5074f33ce82cc138d8872 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Wed, 6 Jul 2005 19:23:41 +0000 Subject: [PATCH] Fix for #1233050 timezone on client. Also got log to use localtime not utc --- log.cc | 2 +- vdr.cc | 32 +++++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/log.cc b/log.cc index 6823f75..c75801b 100644 --- a/log.cc +++ b/log.cc @@ -97,7 +97,7 @@ int Log::log(char *fromModule, int level, char* message, ...) struct timeval tv; gettimeofday(&tv, NULL); - struct tm* tm = gmtime(&tv.tv_sec); + struct tm* tm = localtime(&tv.tv_sec); spaceLeft -= strftime(buffer, spaceLeft, "%H:%M:%S.", tm); spaceLeft -= snprintf(&buffer[150-spaceLeft], spaceLeft, "%06lu ", (unsigned long)tv.tv_usec); diff --git a/vdr.cc b/vdr.cc index 6600856..ecb2e49 100644 --- a/vdr.cc +++ b/vdr.cc @@ -194,7 +194,10 @@ int VDR::doLogin() pthread_mutex_unlock(&mutex); if (!p) return 0; - unsigned long vdrTime = ntohl(*(unsigned long*)p); + int count = 0; + + unsigned long vdrTime = ntohl(*(unsigned long*)&p[count]); + count += sizeof(unsigned long); Log::getInstance()->log("VDR", Log::DEBUG, "vdrtime = %lu", vdrTime); struct timespec currentTime; @@ -204,6 +207,33 @@ int VDR::doLogin() Log::getInstance()->log("VDR", Log::DEBUG, "set clock = %u", b); + // now make a TZ variable and set it + signed int vdrTimeOffset = ntohl(*(signed int*)&p[count]); + Log::getInstance()->log("VDR", Log::DEBUG, "offset = %i", vdrTimeOffset); + + char sign; + int hours; + int minutes; + if (vdrTimeOffset > 0) sign = '-'; + else sign = '+'; + + vdrTimeOffset = abs(vdrTimeOffset); + + hours = (int)vdrTimeOffset / 3600; + minutes = vdrTimeOffset % 3600; + + Log::getInstance()->log("VDR", Log::DEBUG, "%c %i %i", sign, hours, minutes); + + minutes = (int)minutes / 60; + + Log::getInstance()->log("VDR", Log::DEBUG, "%c %i %i", sign, hours, minutes); + + char newTZ[30]; + sprintf(newTZ, "MVP%c%i:%i", sign, hours, minutes); + setenv("TZ", newTZ, 1); + + Log::getInstance()->log("VDR", Log::DEBUG, "Timezone data: %s", newTZ); + free(p); return 1; } -- 2.39.5