aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkripken <alonzakai@gmail.com>2011-07-06 20:25:14 -0700
committerkripken <alonzakai@gmail.com>2011-07-06 20:25:14 -0700
commit3df0ae87665d769b38f31fe7e9870eb3081e8903 (patch)
tree87068307ade1fbcff662fcef5e943d944f4f7374
parente84f1845f1a96ecfda4f1ffc0ba2052dc7c8c86d (diff)
parentdedb83b9e15591893e1b30220c721e447518f5d9 (diff)
Merge pull request #45 from max99x/master
Fixed time.h timezone bug
-rw-r--r--src/library.js6
-rw-r--r--tests/time/output.txt13
-rw-r--r--tests/time/src.c15
3 files changed, 16 insertions, 18 deletions
diff --git a/src/library.js b/src/library.js
index 254f65e8..bf1f28f8 100644
--- a/src/library.js
+++ b/src/library.js
@@ -1792,7 +1792,7 @@ var Library = {
var offset = {{{ makeGetValue('_timezone', 0, 'i32') }}};
var daylight = {{{ makeGetValue('_daylight', 0, 'i32') }}};
daylight = (daylight == 1) ? 60 * 60 : 0;
- var ret = _mktime(tmPtr) - (offset + daylight);
+ var ret = _mktime(tmPtr) + offset - daylight;
return ret;
},
@@ -1817,7 +1817,7 @@ var Library = {
var start = new Date(date.getFullYear(), 0, 1);
var yday = Math.floor((date.getTime() - start.getTime()) / (1000 * 60 * 60 * 24));
{{{ makeSetValue('tmPtr', '___tm_struct_layout.tm_yday', 'yday', 'i32') }}}
- {{{ makeSetValue('tmPtr', '___tm_struct_layout.tm_gmtoff', '-start.getTimezoneOffset() * 60', 'i32') }}}
+ {{{ makeSetValue('tmPtr', '___tm_struct_layout.tm_gmtoff', 'start.getTimezoneOffset() * 60', 'i32') }}}
var dst = Number(start.getTimezoneOffset() != date.getTimezoneOffset());
{{{ makeSetValue('tmPtr', '___tm_struct_layout.tm_isdst', 'dst', 'i32') }}}
@@ -1876,7 +1876,7 @@ var Library = {
if (_tzname !== null) return;
_timezone = _malloc(QUANTUM_SIZE);
- {{{ makeSetValue('_timezone', '0', '(new Date()).getTimezoneOffset() * 60', 'i32') }}}
+ {{{ makeSetValue('_timezone', '0', '-(new Date()).getTimezoneOffset() * 60', 'i32') }}}
_daylight = _malloc(QUANTUM_SIZE);
var winter = new Date(2000, 0, 1);
diff --git a/tests/time/output.txt b/tests/time/output.txt
index c8f31001..ae1fde67 100644
--- a/tests/time/output.txt
+++ b/tests/time/output.txt
@@ -20,9 +20,8 @@ localtime timezone: 1
localtime daylight: 1
localtime tzname: 1
localtime <-> mktime: 1
-old year: 102
-new year: 70
-old year again: 102
+localtime_r(1): 1
+localtime_r(2): 1
time: 1
difftime+: 268848637.000000
difftime-: -268848637.000000
@@ -30,9 +29,9 @@ difftime-: -268848637.000000
2000 days: 366
2001 days: 365
2004 days: 366
-asctime: Wed Dec 25 05:22:43 2002
-old asctime: Wed Dec 25 05:22:43 2002
-new asctime_r: Sat Jul 2 22:33:20 2011
-old asctime again: Wed Dec 25 05:22:43 2002
+asctime: Wed Dec 25 03:22:43 2002
+old asctime: Wed Dec 25 03:22:43 2002
+new asctime_r: Sat Jul 2 19:33:20 2011
+old asctime again: Wed Dec 25 03:22:43 2002
clock: 0
ctime: 0
diff --git a/tests/time/src.c b/tests/time/src.c
index df9ad264..3d4da4c2 100644
--- a/tests/time/src.c
+++ b/tests/time/src.c
@@ -44,8 +44,8 @@ int main() {
// Verify localtime() picks up timezone data.
time_t t2 = xmas2002 - 60 * 60 * 24 * 30 * 6;
tm_ptr = localtime(&t2);
- printf("localtime timezone: %d\n", (timezone + tm_ptr->tm_isdst * 60 * 60 ==
- -tm_ptr->tm_gmtoff));
+ time_t dst_diff = (tm_ptr->tm_isdst == 1) ? tm_ptr->tm_isdst * 60 * 60 : 0;
+ printf("localtime timezone: %d\n", (timezone + tm_ptr->tm_gmtoff == dst_diff));
printf("localtime daylight: %d\n", daylight == tm_ptr->tm_isdst);
printf("localtime tzname: %d\n", (!strcmp(tzname[0], tm_ptr->tm_zone) ||
!strcmp(tzname[1], tm_ptr->tm_zone)));
@@ -57,10 +57,9 @@ int main() {
time_t t3 = 0;
struct tm tm2;
localtime_r(&t3, &tm2);
- printf("old year: %d\n", tm_ptr->tm_year);
- printf("new year: %d\n", tm2.tm_year);
+ printf("localtime_r(1): %d\n", tm2.tm_year != tm_ptr->tm_year);
localtime(&xmas2002);
- printf("old year again: %d\n", tm_ptr->tm_year);
+ printf("localtime_r(2): %d\n", tm2.tm_year != tm_ptr->tm_year);
// Verify time() returns reasonable value (between 2011 and 2030).
time_t t4 = 0;
@@ -79,14 +78,14 @@ int main() {
printf("2004 days: %d\n", dysize(2004));
// Verify asctime() formatting().
- printf("asctime: %s", asctime(localtime(&xmas2002)));
+ printf("asctime: %s", asctime(gmtime(&xmas2002)));
// Verify asctime_r() doesn't clobber static data.
time_t t6 = 1309635200ll;
- tm_ptr = localtime(&xmas2002);
+ tm_ptr = gmtime(&xmas2002);
char* formatted = asctime(tm_ptr);
char buffer[32];
- asctime_r(localtime(&t6), buffer);
+ asctime_r(gmtime(&t6), buffer);
printf("old asctime: %s", formatted);
printf("new asctime_r: %s", buffer);
asctime_r(tm_ptr, buffer);