Project

General

Profile

Bug #148

getSysTime does not return the gmtOffset under linux

Added by Geoffrey McRae - over 14 years ago. Updated about 14 years ago.

Status:
Fixed
Priority:
High
Assignee:
Category:
General
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:
Found in version:
Affected Versions:

Description

according to the man page for getsystemtime, the tz parameter is deprecated and not used, thus the timezone value is always zero.


Files

tzfix.patch (672 Bytes) tzfix.patch Geoffrey McRae -, 2010-05-12 08:41
tzfix.2.patch (1.09 KB) tzfix.2.patch Geoffrey McRae -, 2010-05-13 05:46

History

#1

Updated by Andreas Smas over 14 years ago

  • Status changed from New to Fixed
  • Found in version set to worksforme

It's certainly filled in on my 2.6.31 kernel

Result from getSysTime HTSP method:

time (S64) = 1268777255
timezone (S64) = -60

#2

Updated by Geoffrey McRae - over 14 years ago

  • Status changed from Fixed to Need feedback
  • Found in version deleted (worksforme)

See: http://www.kernel.org/doc/man-pages/online/pages/man2/gettimeofday.2.html

"The use of the timezone structure is obsolete; the tz argument should normally be specified as NULL. The tz_dsttime field has never been used under Linux; it has not been and will not be supported by libc or glibc. Each and every occurrence of this field in the kernel source (other than the declaration) is a bug."

Sample Code:

#include <stdio.h>
#include <sys/time.h>

int main(int argc, char *argv[]) {
        struct timeval tv;
        struct timezone tz;

        memset(&tz, 0xff, sizeof(struct timezone));
        printf("%d %d\n", tz.tz_minuteswest, tz.tz_dsttime);
}

Outputs:

0 0

Kernel:

xbmc:~# uname -a
Linux xbmc 2.6.32-bpo.4-amd64 #1 SMP Thu Apr 8 10:20:24 UTC 2010 x86_64 GNU/Linux

Date output:

xbmc:~# date
Wed Apr 28 17:30:52 EST 2010

#3

Updated by Geoffrey McRae - over 14 years ago

Whoops, posted the wrong test code, that ofc wont ever work, here is the correct code

#include <stdio.h>
#include <sys/time.h>
#include <string.h>

int main(int argc, char *argv[]) {
        struct timeval tv;
        struct timezone tz;

        memset(&tz, 0xff, sizeof(struct timezone));
        gettimeofday(&tv, &tz);
        printf("%d %d\n", tz.tz_minuteswest, tz.tz_dsttime);
}

#4

Updated by Geoffrey McRae - over 14 years ago

Here is the correct way to get the timezone offset:

#include <time.h>
#include <stdio.h>

int main(int argc, char *argv[]) {
        tzset();
        printf("%d\n", timezone);
}

Returns

-36000

Which for me is 10 hours as I am GMT+10 :)

#5

Updated by Geoffrey McRae - over 14 years ago

patch attached, needs testing

#6

Updated by Geoffrey McRae - over 14 years ago

Better patch attached, calls tzset in main as it is not re-entrant.

#7

Updated by Andreas Smas about 14 years ago

  • Status changed from Need feedback to Fixed
  • Found in version set to fixed

Fixed in r5180

Also available in: Atom PDF