mirror of
https://github.com/bellard/quickjs.git
synced 2024-11-25 23:28:12 +08:00
more portable and Windows version for getTimezoneOffset() (github issue #122)
This commit is contained in:
parent
195c42b9fb
commit
e66ce48872
29
quickjs.c
29
quickjs.c
@ -43165,13 +43165,10 @@ static const JSCFunctionListEntry js_math_obj[] = {
|
|||||||
|
|
||||||
/* OS dependent. d = argv[0] is in ms from 1970. Return the difference
|
/* OS dependent. d = argv[0] is in ms from 1970. Return the difference
|
||||||
between UTC time and local time 'd' in minutes */
|
between UTC time and local time 'd' in minutes */
|
||||||
static int getTimezoneOffset(int64_t time) {
|
static int getTimezoneOffset(int64_t time)
|
||||||
#if defined(_WIN32)
|
{
|
||||||
/* XXX: TODO */
|
|
||||||
return 0;
|
|
||||||
#else
|
|
||||||
time_t ti;
|
time_t ti;
|
||||||
struct tm tm;
|
int res;
|
||||||
|
|
||||||
time /= 1000; /* convert to seconds */
|
time /= 1000; /* convert to seconds */
|
||||||
if (sizeof(time_t) == 4) {
|
if (sizeof(time_t) == 4) {
|
||||||
@ -43195,9 +43192,27 @@ static int getTimezoneOffset(int64_t time) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
ti = time;
|
ti = time;
|
||||||
|
#if defined(_WIN32)
|
||||||
|
{
|
||||||
|
struct tm *tm;
|
||||||
|
time_t gm_ti, loc_ti;
|
||||||
|
|
||||||
|
tm = gmtime(&ti);
|
||||||
|
gm_ti = mktime(tm);
|
||||||
|
|
||||||
|
tm = localtime(&ti);
|
||||||
|
loc_ti = mktime(tm);
|
||||||
|
|
||||||
|
res = (gm_ti - loc_ti) / 60;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
{
|
||||||
|
struct tm tm;
|
||||||
localtime_r(&ti, &tm);
|
localtime_r(&ti, &tm);
|
||||||
return -tm.tm_gmtoff / 60;
|
res = -tm.tm_gmtoff / 60;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
|
Loading…
Reference in New Issue
Block a user