Browse Source

Force tm_isdst to 0 before mktime()

Forcing tm_isdst to 0 before mktime() and removing a previous DST check
after mktime() seems to work on Linux and should (potentially) fix a
RISC OS issue.
pull/407/head
Sami Vaarala 9 years ago
parent
commit
22e631a640
  1. 12
      src/duk_bi_date_unix.c

12
src/duk_bi_date_unix.c

@ -152,6 +152,13 @@ DUK_INTERNAL duk_int_t duk_bi_date_get_local_tzoffset_gmtime(duk_double_t d) {
(long) tms[1].tm_mday, (long) tms[1].tm_mon, (long) tms[1].tm_year, (long) tms[1].tm_mday, (long) tms[1].tm_mon, (long) tms[1].tm_year,
(long) tms[1].tm_wday, (long) tms[1].tm_yday, (long) tms[1].tm_isdst)); (long) tms[1].tm_wday, (long) tms[1].tm_yday, (long) tms[1].tm_isdst));
/* tm_isdst is both an input and an output to mktime(), use 0 to
* avoid DST handling in mktime():
* - https://github.com/svaarala/duktape/issues/406
* - http://stackoverflow.com/questions/8558919/mktime-and-tm-isdst
*/
tms[0].tm_isdst = 0;
tms[1].tm_isdst = 0;
t1 = mktime(&tms[0]); /* UTC */ t1 = mktime(&tms[0]); /* UTC */
t2 = mktime(&tms[1]); /* local */ t2 = mktime(&tms[1]); /* local */
if (t1 == (time_t) -1 || t2 == (time_t) -1) { if (t1 == (time_t) -1 || t2 == (time_t) -1) {
@ -162,11 +169,6 @@ DUK_INTERNAL duk_int_t duk_bi_date_get_local_tzoffset_gmtime(duk_double_t d) {
*/ */
goto error; goto error;
} }
if (tms[1].tm_isdst > 0) {
t2 += 3600;
} else if (tms[1].tm_isdst < 0) {
DUK_D(DUK_DPRINT("tm_isdst is negative: %d", (int) tms[1].tm_isdst));
}
DUK_DDD(DUK_DDDPRINT("t1=%ld (utc), t2=%ld (local)", (long) t1, (long) t2)); DUK_DDD(DUK_DDDPRINT("t1=%ld (utc), t2=%ld (local)", (long) t1, (long) t2));
/* Compute final offset in seconds, positive if local time ahead of /* Compute final offset in seconds, positive if local time ahead of

Loading…
Cancel
Save