Merge pull request #45 from max99x/master

Fixed time.h timezone bug
This commit is contained in:
kripken 2011-07-06 20:25:14 -07:00
Родитель e84f1845f1 dedb83b9e1
Коммит 3df0ae8766
3 изменённых файлов: 16 добавлений и 18 удалений

Просмотреть файл

@ -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);

Просмотреть файл

@ -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

Просмотреть файл

@ -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);