未验证 提交 f6776e1c 编写于 作者: D dapan1121 提交者: GitHub

Merge pull request #20623 from taosdata/fix/TD-23217

fix: fix windows handling localtime_s error
...@@ -413,12 +413,16 @@ struct tm *taosLocalTime(const time_t *timep, struct tm *result) { ...@@ -413,12 +413,16 @@ struct tm *taosLocalTime(const time_t *timep, struct tm *result) {
} }
#ifdef WINDOWS #ifdef WINDOWS
if (*timep < 0) { if (*timep < 0) {
return NULL;
// TODO: bugs in following code
SYSTEMTIME ss, s; SYSTEMTIME ss, s;
FILETIME ff, f; FILETIME ff, f;
LARGE_INTEGER offset; LARGE_INTEGER offset;
struct tm tm1; struct tm tm1;
time_t tt = 0; time_t tt = 0;
localtime_s(&tm1, &tt); if (localtime_s(&tm1, &tt) != 0 ) {
return NULL;
}
ss.wYear = tm1.tm_year + 1900; ss.wYear = tm1.tm_year + 1900;
ss.wMonth = tm1.tm_mon + 1; ss.wMonth = tm1.tm_mon + 1;
ss.wDay = tm1.tm_mday; ss.wDay = tm1.tm_mday;
...@@ -444,7 +448,9 @@ struct tm *taosLocalTime(const time_t *timep, struct tm *result) { ...@@ -444,7 +448,9 @@ struct tm *taosLocalTime(const time_t *timep, struct tm *result) {
result->tm_yday = 0; result->tm_yday = 0;
result->tm_isdst = 0; result->tm_isdst = 0;
} else { } else {
localtime_s(result, timep); if (localtime_s(result, timep) != 0) {
return NULL;
}
} }
#else #else
localtime_r(timep, result); localtime_r(timep, result);
...@@ -469,12 +475,16 @@ struct tm *taosLocalTimeNolock(struct tm *result, const time_t *timep, int dst) ...@@ -469,12 +475,16 @@ struct tm *taosLocalTimeNolock(struct tm *result, const time_t *timep, int dst)
} }
#ifdef WINDOWS #ifdef WINDOWS
if (*timep < 0) { if (*timep < 0) {
return NULL;
// TODO: bugs in following code
SYSTEMTIME ss, s; SYSTEMTIME ss, s;
FILETIME ff, f; FILETIME ff, f;
LARGE_INTEGER offset; LARGE_INTEGER offset;
struct tm tm1; struct tm tm1;
time_t tt = 0; time_t tt = 0;
localtime_s(&tm1, &tt); if (localtime_s(&tm1, &tt) != 0) {
return NULL;
}
ss.wYear = tm1.tm_year + 1900; ss.wYear = tm1.tm_year + 1900;
ss.wMonth = tm1.tm_mon + 1; ss.wMonth = tm1.tm_mon + 1;
ss.wDay = tm1.tm_mday; ss.wDay = tm1.tm_mday;
...@@ -500,7 +510,9 @@ struct tm *taosLocalTimeNolock(struct tm *result, const time_t *timep, int dst) ...@@ -500,7 +510,9 @@ struct tm *taosLocalTimeNolock(struct tm *result, const time_t *timep, int dst)
result->tm_yday = 0; result->tm_yday = 0;
result->tm_isdst = 0; result->tm_isdst = 0;
} else { } else {
localtime_s(result, timep); if (localtime_s(result, timep) != 0) {
return NULL;
}
} }
#elif defined(LINUX) #elif defined(LINUX)
time_t secsMin = 60, secsHour = 3600, secsDay = 3600 * 24; time_t secsMin = 60, secsHour = 3600, secsDay = 3600 * 24;
......
...@@ -291,7 +291,10 @@ char *shellFormatTimestamp(char *buf, int64_t val, int32_t precision) { ...@@ -291,7 +291,10 @@ char *shellFormatTimestamp(char *buf, int64_t val, int32_t precision) {
} }
struct tm ptm = {0}; struct tm ptm = {0};
taosLocalTime(&tt, &ptm); if (taosLocalTime(&tt, &ptm) == NULL) {
sprintf(buf, "NaN");
return buf;
}
size_t pos = strftime(buf, 35, "%Y-%m-%d %H:%M:%S", &ptm); size_t pos = strftime(buf, 35, "%Y-%m-%d %H:%M:%S", &ptm);
if (precision == TSDB_TIME_PRECISION_NANO) { if (precision == TSDB_TIME_PRECISION_NANO) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册