[M3devel] time conversion problems : Date.ToTime on AMD64_LINUX
Mika Nystrom
mika at async.caltech.edu
Mon Apr 11 00:45:16 CEST 2011
Hello m3devel (especially Jay),
I'm having some time conversion problems. I *believe* (a bit hard to
verify because m3gdb isn't working!!) that Date.ToTime called on
Jan 1 1970 in timezone "UTC" or "GMT" is returning -3600 for me.
I note the following (fairly recent) code in DatePosixC.c:
#ifdef _TIME64_T
t = mktime64(&tm);
#else
t = mktime(&tm);
#endif
#ifdef DATE_BSD
if (t == -1)
goto Exit;
/* adjust result to reflect "date->offset" */
#ifdef _TIME64_T
time64(&now);
local_now = localtime64(&now);
#else
time(&now);
local_now = localtime(&now);
#endif
assert(local_now != NULL);
if (local_now->tm_isdst > 0)
/* decrement the local time zone by one hour if DST is in effect */
local_now->m3_tm_gmtoff -= SecsPerHour;
/* As above, we must negate "date->offset" to account for the
opposite sense of that field compared to Unix. */
t -= ((-date->offset) - local_now->m3_tm_gmtoff);
Exit:
#endif
return t;
What I don't understand is the subtracting off of SecsPerHour if
"now" is DST. Yeah, now is DST (it's April), but the time I'm
converting was in the winter, and besides GMT and UTC don't even
have DST.
I don't understand the intent of the code.. can someone explain why
we're subtracting off an hour? And why is it based on the value of
tm_isdst of the *current* time? Some additional documentation within
the file would be helpful too.
Note my conversion returns the correct 0 on various other M3
implementations.
Note the system time on my system is in a timezone that has DST
(namely, BST) but I have changed the TZ environment variable to UTC or GMT
before calling this code.
Mika
More information about the M3devel
mailing list