From 02f88d54098ee3648d740e906a86c247539c344e Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Thu, 29 Jul 2021 13:03:18 +0800 Subject: [PATCH] [TD-5505]: add support for parsing timestamp with both letter 'T' and whitespace as timezone indicator --- src/os/src/detail/osTime.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/os/src/detail/osTime.c b/src/os/src/detail/osTime.c index 8db3fed701..c7a249c2e3 100644 --- a/src/os/src/detail/osTime.c +++ b/src/os/src/detail/osTime.c @@ -85,6 +85,7 @@ 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); static int32_t parseLocaltimeWithDst(char* timestr, int64_t* time, int32_t timePrec); +static char* forwardToTimeStringEnd(char* str); static int32_t (*parseLocaltimeFp[]) (char* timestr, int64_t* time, int32_t timePrec) = { parseLocaltime, @@ -95,9 +96,12 @@ 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) { /* parse datatime string in with tz */ + char *seg = forwardToTimeStringEnd(timestr); if (strnchr(timestr, 'T', len, false) != NULL) { return parseTimeWithTz(timestr, time, timePrec, 'T'); - } else if (strnchr(timestr, ' ', len, false) != NULL) { + } else if (strnchr(timestr, ' ', len, false) != NULL && + (strnchr(seg, 'Z', len, false) != NULL || strnchr(seg, 'z', len, false) != NULL || + strnchr(seg, '+', len, false) != NULL || strnchr(seg, '-', len, false) != NULL)) { return parseTimeWithTz(timestr, time, timePrec, ' '); } else { return (*parseLocaltimeFp[day_light])(timestr, time, timePrec); -- GitLab