提交 af92dc63 编写于 作者: G Ganlin Zhao

Merge branch 'develop' into feature/TD-13970

上级 a590ecf0
...@@ -83,26 +83,26 @@ void deltaToUtcInitOnce() { ...@@ -83,26 +83,26 @@ void deltaToUtcInitOnce() {
static int64_t parseFraction(char* str, char** end, int32_t timePrec); 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 parseTimeWithTz(char* timestr, int64_t* time, int32_t timePrec, char delim);
static int32_t parseLocaltime(char* timestr, int64_t* time, int32_t timePrec); static int32_t parseLocaltime(char* timestr, int64_t* time, int32_t timePrec, char delim, bool withDST);
static int32_t parseLocaltimeWithDst(char* timestr, int64_t* time, int32_t timePrec);
static char* forwardToTimeStringEnd(char* str); static char* forwardToTimeStringEnd(char* str);
static bool checkTzPresent(char *str, int32_t len); static bool checkTzPresent(char *str, int32_t len);
static int32_t (*parseLocaltimeFp[]) (char* timestr, int64_t* time, int32_t timePrec) = {
parseLocaltime,
parseLocaltimeWithDst
};
int32_t taosGetTimestampSec() { return (int32_t)time(NULL); } 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) { int32_t taosParseTime(char* timestr, int64_t* time, int32_t len, int32_t timePrec, int8_t day_light) {
/* parse datatime string in with tz */ /* parse datatime string in with tz */
if (strnchr(timestr, 'T', len, false) != NULL) { if (strnchr(timestr, 'T', len, false) != NULL) {
return parseTimeWithTz(timestr, time, timePrec, 'T'); if (checkTzPresent(timestr, len)) {
} else if (checkTzPresent(timestr, len)) { return parseTimeWithTz(timestr, time, timePrec, 'T');
return parseTimeWithTz(timestr, time, timePrec, 0); } else {
return parseLocaltime(timestr, time, timePrec, 'T', day_light);
}
} else { } else {
return (*parseLocaltimeFp[day_light])(timestr, time, timePrec); if (checkTzPresent(timestr, len)) {
return parseTimeWithTz(timestr, time, timePrec, 0);
} else {
return parseLocaltime(timestr, time, timePrec, 0, day_light);
}
} }
} }
...@@ -316,9 +316,12 @@ int32_t parseTimeWithTz(char* timestr, int64_t* time, int32_t timePrec, char del ...@@ -316,9 +316,12 @@ int32_t parseTimeWithTz(char* timestr, int64_t* time, int32_t timePrec, char del
return 0; return 0;
} }
int32_t parseLocaltime(char* timestr, int64_t* time, int32_t timePrec) { int32_t parseLocaltime(char* timestr, int64_t* time, int32_t timePrec, char delim, bool withDST) {
*time = 0; *time = 0;
struct tm tm = {0}; struct tm tm = {0};
if (withDST) {
tm.tm_isdst = -1;
}
char* str = strptime(timestr, "%Y-%m-%d %H:%M:%S", &tm); char* str = strptime(timestr, "%Y-%m-%d %H:%M:%S", &tm);
if (str == NULL) { if (str == NULL) {
...@@ -335,41 +338,14 @@ int32_t parseLocaltime(char* timestr, int64_t* time, int32_t timePrec) { ...@@ -335,41 +338,14 @@ int32_t parseLocaltime(char* timestr, int64_t* time, int32_t timePrec) {
#endif #endif
#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 seconds;
if (!withDST) {
int64_t fraction = 0; 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 {
if (*str == '.') { /* mktime will be affected by TZ, set by using taos_options */
/* parse the second fraction part */ seconds = mktime(&tm);
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) {
*time = 0;
struct tm tm = {0};
tm.tm_isdst = -1;
char* str = strptime(timestr, "%Y-%m-%d %H:%M:%S", &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; int64_t fraction = 0;
if (*str == '.') { if (*str == '.') {
...@@ -382,6 +358,7 @@ int32_t parseLocaltimeWithDst(char* timestr, int64_t* time, int32_t timePrec) { ...@@ -382,6 +358,7 @@ int32_t parseLocaltimeWithDst(char* timestr, int64_t* time, int32_t timePrec) {
int64_t factor = (timePrec == TSDB_TIME_PRECISION_MILLI) ? 1000 : int64_t factor = (timePrec == TSDB_TIME_PRECISION_MILLI) ? 1000 :
(timePrec == TSDB_TIME_PRECISION_MICRO ? 1000000 : 1000000000); (timePrec == TSDB_TIME_PRECISION_MICRO ? 1000000 : 1000000000);
*time = factor * seconds + fraction; *time = factor * seconds + fraction;
return 0; return 0;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册