From a022b4a9ba4c440cbf95a8281727e06e17f2c51b Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Tue, 15 Mar 2022 19:17:56 +0800 Subject: [PATCH] Merge branch 'develop' into feature/TD-13970 --- src/os/src/detail/osTime.c | 63 ++++++++------------------------------ 1 file changed, 13 insertions(+), 50 deletions(-) diff --git a/src/os/src/detail/osTime.c b/src/os/src/detail/osTime.c index 073d0eed89..1575b3100f 100644 --- a/src/os/src/detail/osTime.c +++ b/src/os/src/detail/osTime.c @@ -83,16 +83,10 @@ void deltaToUtcInitOnce() { static int64_t parseFraction(char* str, char** end, int32_t timePrec); static int32_t parseTimeWithTz(char* timestr, int64_t* time, int32_t timePrec, char delim); -static int32_t parseLocaltime(char* timestr, int64_t* time, int32_t timePrec, char delim); -static int32_t parseLocaltimeWithDst(char* timestr, int64_t* time, int32_t timePrec, char delim); +static int32_t parseLocaltime(char* timestr, int64_t* time, int32_t timePrec, char delim, bool withDST); static char* forwardToTimeStringEnd(char* str); static bool checkTzPresent(char *str, int32_t len); -static int32_t (*parseLocaltimeFp[]) (char* timestr, int64_t* time, int32_t timePrec, char delim) = { - parseLocaltime, - parseLocaltimeWithDst -}; - int32_t taosGetTimestampSec() { return (int32_t)time(NULL); } int32_t taosParseTime(char* timestr, int64_t* time, int32_t len, int32_t timePrec, int8_t day_light) { @@ -101,13 +95,13 @@ int32_t taosParseTime(char* timestr, int64_t* time, int32_t len, int32_t timePre if (checkTzPresent(timestr, len)) { return parseTimeWithTz(timestr, time, timePrec, 'T'); } else { - return (*parseLocaltimeFp[day_light])(timestr, time, timePrec, 'T'); + return parseLocaltime(timestr, time, timePrec, 'T', day_light); } } else { if (checkTzPresent(timestr, len)) { return parseTimeWithTz(timestr, time, timePrec, 0); } else { - return (*parseLocaltimeFp[day_light])(timestr, time, timePrec, 0); + return parseLocaltime(timestr, time, timePrec, 0, day_light); } } } @@ -322,9 +316,12 @@ int32_t parseTimeWithTz(char* timestr, int64_t* time, int32_t timePrec, char del return 0; } -int32_t parseLocaltime(char* timestr, int64_t* time, int32_t timePrec, char delim) { +int32_t parseLocaltime(char* timestr, int64_t* time, int32_t timePrec, char delim, bool withDST) { *time = 0; struct tm tm = {0}; + if (withDST) { + tm.tm_isdst = -1; + } char* str; if (delim == 'T') { @@ -349,49 +346,14 @@ int32_t parseLocaltime(char* timestr, int64_t* time, int32_t timePrec, char deli #endif #endif - int64_t seconds = user_mktime64(tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, timezone); - - int64_t fraction = 0; - - if (*str == '.') { - /* parse the second fraction part */ - if ((fraction = parseFraction(str + 1, &str, timePrec)) < 0) { - return -1; - } - } - - int64_t factor = (timePrec == TSDB_TIME_PRECISION_MILLI) ? 1000 : - (timePrec == TSDB_TIME_PRECISION_MICRO ? 1000000 : 1000000000); - *time = factor * seconds + fraction; - - return 0; -} - -int32_t parseLocaltimeWithDst(char* timestr, int64_t* time, int32_t timePrec, char delim) { - *time = 0; - struct tm tm = {0}; - tm.tm_isdst = -1; - - char* str; - if (delim == 'T') { - str = strptime(timestr, "%Y-%m-%dT%H:%M:%S", &tm); - } else if (delim == 0) { - str = strptime(timestr, "%Y-%m-%d %H:%M:%S", &tm); + int64_t seconds; + if (!withDST) { + seconds = user_mktime64(tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, timezone); } else { - str = NULL; + /* mktime will be affected by TZ, set by using taos_options */ + seconds = mktime(&tm); } - if (str == NULL) { - //if parse failed, try "%Y-%m-%d" format - str = strptime(timestr, "%Y-%m-%d", &tm); - if (str == NULL) { - return -1; - } - } - - /* mktime will be affected by TZ, set by using taos_options */ - int64_t seconds = mktime(&tm); - int64_t fraction = 0; if (*str == '.') { @@ -404,6 +366,7 @@ int32_t parseLocaltimeWithDst(char* timestr, int64_t* time, int32_t timePrec, ch int64_t factor = (timePrec == TSDB_TIME_PRECISION_MILLI) ? 1000 : (timePrec == TSDB_TIME_PRECISION_MICRO ? 1000000 : 1000000000); *time = factor * seconds + fraction; + return 0; } -- GitLab