Merge pull request #24550 from taosdata/fix/xsren/TS-4454/timezoneOnWindows
fix: timezone error on windows
This commit is contained in:
commit
81c83b67d4
|
@ -37,9 +37,6 @@
|
||||||
// This magic number is the number of 100 nanosecond intervals since January 1, 1601 (UTC)
|
// This magic number is the number of 100 nanosecond intervals since January 1, 1601 (UTC)
|
||||||
// until 00:00:00 January 1, 1970
|
// until 00:00:00 January 1, 1970
|
||||||
static const uint64_t TIMEEPOCH = ((uint64_t)116444736000000000ULL);
|
static const uint64_t TIMEEPOCH = ((uint64_t)116444736000000000ULL);
|
||||||
// This magic number is the number of 100 nanosecond intervals since January 1, 1601 (UTC)
|
|
||||||
// until 00:00:00 January 1, 1900
|
|
||||||
static const uint64_t TIMEEPOCH1900 = ((uint64_t)116445024000000000ULL);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We do not implement alternate representations. However, we always
|
* We do not implement alternate representations. However, we always
|
||||||
|
@ -360,6 +357,7 @@ int32_t taosGetTimeOfDay(struct timeval *tv) {
|
||||||
t.QuadPart -= TIMEEPOCH;
|
t.QuadPart -= TIMEEPOCH;
|
||||||
tv->tv_sec = t.QuadPart / 10000000;
|
tv->tv_sec = t.QuadPart / 10000000;
|
||||||
tv->tv_usec = (t.QuadPart % 10000000) / 10;
|
tv->tv_usec = (t.QuadPart % 10000000) / 10;
|
||||||
|
return 0;
|
||||||
#else
|
#else
|
||||||
return gettimeofday(tv, NULL);
|
return gettimeofday(tv, NULL);
|
||||||
#endif
|
#endif
|
||||||
|
@ -482,33 +480,51 @@ struct tm *taosLocalTime(const time_t *timep, struct tm *result, char *buf) {
|
||||||
sprintf(buf, "NaN");
|
sprintf(buf, "NaN");
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
} else if (*timep < 0) {
|
||||||
|
SYSTEMTIME ss, s;
|
||||||
|
FILETIME ff, f;
|
||||||
|
|
||||||
SYSTEMTIME s;
|
LARGE_INTEGER offset;
|
||||||
FILETIME f;
|
struct tm tm1;
|
||||||
LARGE_INTEGER offset;
|
time_t tt = 0;
|
||||||
struct tm tm1;
|
if (localtime_s(&tm1, &tt) != 0) {
|
||||||
time_t tt = 0;
|
if (buf != NULL) {
|
||||||
if (localtime_s(&tm1, &tt) != 0) {
|
sprintf(buf, "NaN");
|
||||||
if (buf != NULL) {
|
}
|
||||||
sprintf(buf, "NaN");
|
return NULL;
|
||||||
|
}
|
||||||
|
ss.wYear = tm1.tm_year + 1900;
|
||||||
|
ss.wMonth = tm1.tm_mon + 1;
|
||||||
|
ss.wDay = tm1.tm_mday;
|
||||||
|
ss.wHour = tm1.tm_hour;
|
||||||
|
ss.wMinute = tm1.tm_min;
|
||||||
|
ss.wSecond = tm1.tm_sec;
|
||||||
|
ss.wMilliseconds = 0;
|
||||||
|
SystemTimeToFileTime(&ss, &ff);
|
||||||
|
offset.QuadPart = ff.dwHighDateTime;
|
||||||
|
offset.QuadPart <<= 32;
|
||||||
|
offset.QuadPart |= ff.dwLowDateTime;
|
||||||
|
offset.QuadPart += *timep * 10000000;
|
||||||
|
f.dwLowDateTime = offset.QuadPart & 0xffffffff;
|
||||||
|
f.dwHighDateTime = (offset.QuadPart >> 32) & 0xffffffff;
|
||||||
|
FileTimeToSystemTime(&f, &s);
|
||||||
|
result->tm_sec = s.wSecond;
|
||||||
|
result->tm_min = s.wMinute;
|
||||||
|
result->tm_hour = s.wHour;
|
||||||
|
result->tm_mday = s.wDay;
|
||||||
|
result->tm_mon = s.wMonth - 1;
|
||||||
|
result->tm_year = s.wYear - 1900;
|
||||||
|
result->tm_wday = s.wDayOfWeek;
|
||||||
|
result->tm_yday = 0;
|
||||||
|
result->tm_isdst = 0;
|
||||||
|
} else {
|
||||||
|
if (localtime_s(result, timep) != 0) {
|
||||||
|
if (buf != NULL) {
|
||||||
|
sprintf(buf, "NaN");
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
offset.QuadPart = TIMEEPOCH1900;
|
|
||||||
offset.QuadPart += *timep * 10000000;
|
|
||||||
f.dwLowDateTime = offset.QuadPart & 0xffffffff;
|
|
||||||
f.dwHighDateTime = (offset.QuadPart >> 32) & 0xffffffff;
|
|
||||||
FileTimeToSystemTime(&f, &s);
|
|
||||||
result->tm_sec = s.wSecond;
|
|
||||||
result->tm_min = s.wMinute;
|
|
||||||
result->tm_hour = s.wHour;
|
|
||||||
result->tm_mday = s.wDay;
|
|
||||||
result->tm_mon = s.wMonth - 1;
|
|
||||||
result->tm_year = s.wYear - 1900;
|
|
||||||
result->tm_wday = s.wDayOfWeek;
|
|
||||||
result->tm_yday = 0;
|
|
||||||
result->tm_isdst = 0;
|
|
||||||
#else
|
#else
|
||||||
res = localtime_r(timep, result);
|
res = localtime_r(timep, result);
|
||||||
if (res == NULL && buf != NULL) {
|
if (res == NULL && buf != NULL) {
|
||||||
|
|
Loading…
Reference in New Issue