Коммит
3df0ae8766
|
@ -1792,7 +1792,7 @@ var Library = {
|
||||||
var offset = {{{ makeGetValue('_timezone', 0, 'i32') }}};
|
var offset = {{{ makeGetValue('_timezone', 0, 'i32') }}};
|
||||||
var daylight = {{{ makeGetValue('_daylight', 0, 'i32') }}};
|
var daylight = {{{ makeGetValue('_daylight', 0, 'i32') }}};
|
||||||
daylight = (daylight == 1) ? 60 * 60 : 0;
|
daylight = (daylight == 1) ? 60 * 60 : 0;
|
||||||
var ret = _mktime(tmPtr) - (offset + daylight);
|
var ret = _mktime(tmPtr) + offset - daylight;
|
||||||
return ret;
|
return ret;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -1817,7 +1817,7 @@ var Library = {
|
||||||
var start = new Date(date.getFullYear(), 0, 1);
|
var start = new Date(date.getFullYear(), 0, 1);
|
||||||
var yday = Math.floor((date.getTime() - start.getTime()) / (1000 * 60 * 60 * 24));
|
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_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());
|
var dst = Number(start.getTimezoneOffset() != date.getTimezoneOffset());
|
||||||
{{{ makeSetValue('tmPtr', '___tm_struct_layout.tm_isdst', 'dst', 'i32') }}}
|
{{{ makeSetValue('tmPtr', '___tm_struct_layout.tm_isdst', 'dst', 'i32') }}}
|
||||||
|
@ -1876,7 +1876,7 @@ var Library = {
|
||||||
if (_tzname !== null) return;
|
if (_tzname !== null) return;
|
||||||
|
|
||||||
_timezone = _malloc(QUANTUM_SIZE);
|
_timezone = _malloc(QUANTUM_SIZE);
|
||||||
{{{ makeSetValue('_timezone', '0', '(new Date()).getTimezoneOffset() * 60', 'i32') }}}
|
{{{ makeSetValue('_timezone', '0', '-(new Date()).getTimezoneOffset() * 60', 'i32') }}}
|
||||||
|
|
||||||
_daylight = _malloc(QUANTUM_SIZE);
|
_daylight = _malloc(QUANTUM_SIZE);
|
||||||
var winter = new Date(2000, 0, 1);
|
var winter = new Date(2000, 0, 1);
|
||||||
|
|
|
@ -20,9 +20,8 @@ localtime timezone: 1
|
||||||
localtime daylight: 1
|
localtime daylight: 1
|
||||||
localtime tzname: 1
|
localtime tzname: 1
|
||||||
localtime <-> mktime: 1
|
localtime <-> mktime: 1
|
||||||
old year: 102
|
localtime_r(1): 1
|
||||||
new year: 70
|
localtime_r(2): 1
|
||||||
old year again: 102
|
|
||||||
time: 1
|
time: 1
|
||||||
difftime+: 268848637.000000
|
difftime+: 268848637.000000
|
||||||
difftime-: -268848637.000000
|
difftime-: -268848637.000000
|
||||||
|
@ -30,9 +29,9 @@ difftime-: -268848637.000000
|
||||||
2000 days: 366
|
2000 days: 366
|
||||||
2001 days: 365
|
2001 days: 365
|
||||||
2004 days: 366
|
2004 days: 366
|
||||||
asctime: Wed Dec 25 05:22:43 2002
|
asctime: Wed Dec 25 03:22:43 2002
|
||||||
old asctime: Wed Dec 25 05:22:43 2002
|
old asctime: Wed Dec 25 03:22:43 2002
|
||||||
new asctime_r: Sat Jul 2 22:33:20 2011
|
new asctime_r: Sat Jul 2 19:33:20 2011
|
||||||
old asctime again: Wed Dec 25 05:22:43 2002
|
old asctime again: Wed Dec 25 03:22:43 2002
|
||||||
clock: 0
|
clock: 0
|
||||||
ctime: 0
|
ctime: 0
|
||||||
|
|
|
@ -44,8 +44,8 @@ int main() {
|
||||||
// Verify localtime() picks up timezone data.
|
// Verify localtime() picks up timezone data.
|
||||||
time_t t2 = xmas2002 - 60 * 60 * 24 * 30 * 6;
|
time_t t2 = xmas2002 - 60 * 60 * 24 * 30 * 6;
|
||||||
tm_ptr = localtime(&t2);
|
tm_ptr = localtime(&t2);
|
||||||
printf("localtime timezone: %d\n", (timezone + tm_ptr->tm_isdst * 60 * 60 ==
|
time_t dst_diff = (tm_ptr->tm_isdst == 1) ? tm_ptr->tm_isdst * 60 * 60 : 0;
|
||||||
-tm_ptr->tm_gmtoff));
|
printf("localtime timezone: %d\n", (timezone + tm_ptr->tm_gmtoff == dst_diff));
|
||||||
printf("localtime daylight: %d\n", daylight == tm_ptr->tm_isdst);
|
printf("localtime daylight: %d\n", daylight == tm_ptr->tm_isdst);
|
||||||
printf("localtime tzname: %d\n", (!strcmp(tzname[0], tm_ptr->tm_zone) ||
|
printf("localtime tzname: %d\n", (!strcmp(tzname[0], tm_ptr->tm_zone) ||
|
||||||
!strcmp(tzname[1], tm_ptr->tm_zone)));
|
!strcmp(tzname[1], tm_ptr->tm_zone)));
|
||||||
|
@ -57,10 +57,9 @@ int main() {
|
||||||
time_t t3 = 0;
|
time_t t3 = 0;
|
||||||
struct tm tm2;
|
struct tm tm2;
|
||||||
localtime_r(&t3, &tm2);
|
localtime_r(&t3, &tm2);
|
||||||
printf("old year: %d\n", tm_ptr->tm_year);
|
printf("localtime_r(1): %d\n", tm2.tm_year != tm_ptr->tm_year);
|
||||||
printf("new year: %d\n", tm2.tm_year);
|
|
||||||
localtime(&xmas2002);
|
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).
|
// Verify time() returns reasonable value (between 2011 and 2030).
|
||||||
time_t t4 = 0;
|
time_t t4 = 0;
|
||||||
|
@ -79,14 +78,14 @@ int main() {
|
||||||
printf("2004 days: %d\n", dysize(2004));
|
printf("2004 days: %d\n", dysize(2004));
|
||||||
|
|
||||||
// Verify asctime() formatting().
|
// Verify asctime() formatting().
|
||||||
printf("asctime: %s", asctime(localtime(&xmas2002)));
|
printf("asctime: %s", asctime(gmtime(&xmas2002)));
|
||||||
|
|
||||||
// Verify asctime_r() doesn't clobber static data.
|
// Verify asctime_r() doesn't clobber static data.
|
||||||
time_t t6 = 1309635200ll;
|
time_t t6 = 1309635200ll;
|
||||||
tm_ptr = localtime(&xmas2002);
|
tm_ptr = gmtime(&xmas2002);
|
||||||
char* formatted = asctime(tm_ptr);
|
char* formatted = asctime(tm_ptr);
|
||||||
char buffer[32];
|
char buffer[32];
|
||||||
asctime_r(localtime(&t6), buffer);
|
asctime_r(gmtime(&t6), buffer);
|
||||||
printf("old asctime: %s", formatted);
|
printf("old asctime: %s", formatted);
|
||||||
printf("new asctime_r: %s", buffer);
|
printf("new asctime_r: %s", buffer);
|
||||||
asctime_r(tm_ptr, buffer);
|
asctime_r(tm_ptr, buffer);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче