fix:[TD-33285]gmtime return error in windows

This commit is contained in:
wangmm0220 2024-12-24 14:26:07 +08:00
parent 5934324f3d
commit efde801b7e
2 changed files with 31 additions and 1 deletions

View File

@ -454,7 +454,8 @@ struct tm *taosGmTimeR(const time_t *timep, struct tm *result) {
return NULL; return NULL;
} }
#ifdef WINDOWS #ifdef WINDOWS
return gmtime_s(result, timep); errno_t code = gmtime_s(result, timep);
return (code == 0) ? result : NULL;
#else #else
return gmtime_r(timep, result); return gmtime_r(timep, result);
#endif #endif

View File

@ -94,6 +94,35 @@ TEST(osTimeTests, taosLocalTime) {
#endif #endif
} }
TEST(osTimeTests, taosGmTimeR) {
// Test 1: Test when both timep and result are not NULL
time_t timep = 1617531000; // 2021-04-04 18:10:00
struct tm tmInfo;
ASSERT_NE(taosGmTimeR(&timep, &tmInfo), nullptr);
char buf[128];
taosStrfTime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%S", &tmInfo);
ASSERT_STREQ(buf, "2021-04-04T10:10:00");
}
TEST(osTimeTests, taosTimeGm) {
char *timestr= "2021-04-04T18:10:00";
struct tm tm = {0};
taosStrpTime(timestr, "%Y-%m-%dT%H:%M:%S", &tm);
int64_t seconds = taosTimeGm(&tm);
ASSERT_EQ(seconds, 1617559800);
}
TEST(osTimeTests, taosMktime) {
char *timestr= "2021-04-04T18:10:00";
struct tm tm = {0};
taosStrpTime(timestr, "%Y-%m-%dT%H:%M:%S", &tm);
time_t seconds = taosMktime(&tm, NULL);
ASSERT_EQ(seconds, 1617531000);
}
TEST(osTimeTests, invalidParameter) { TEST(osTimeTests, invalidParameter) {
void *retp = NULL; void *retp = NULL;
int32_t reti = 0; int32_t reti = 0;