From ba8a410d6d88ebe285197046c9f8dd127795b69b Mon Sep 17 00:00:00 2001 From: Bob Liu Date: Sun, 12 Nov 2023 19:15:41 +0800 Subject: [PATCH] fix toISO8601Function --- include/common/ttime.h | 7 +++++++ source/common/src/ttime.c | 4 ++++ source/libs/scalar/src/sclfunc.c | 9 +++++++++ 3 files changed, 20 insertions(+) diff --git a/include/common/ttime.h b/include/common/ttime.h index 306b5105d0..1dfa609064 100644 --- a/include/common/ttime.h +++ b/include/common/ttime.h @@ -118,6 +118,13 @@ int32_t taosChar2Ts(const char* format, SArray** formats, const char* tsStr, int void TEST_ts2char(const char* format, int64_t ts, int32_t precision, char* out, int32_t outLen); int32_t TEST_char2ts(const char* format, int64_t* ts, int32_t precision, const char* tsStr); +/// @brief get offset seconds from zero timezone to input timezone +/// for +XX timezone, the offset to zero is negative value +/// @param tzStr timezonestr, eg: +0800, -0830, -08 +/// @param offset seconds, eg: +08 offset -28800, -01 offset 3600 +/// @return 0 success, other fail +int32_t offsetOfTimezone(char* tzStr, int64_t* offset); + #ifdef __cplusplus } #endif diff --git a/source/common/src/ttime.c b/source/common/src/ttime.c index a701c88a24..385be92774 100644 --- a/source/common/src/ttime.c +++ b/source/common/src/ttime.c @@ -194,6 +194,10 @@ int32_t parseTimezone(char* str, int64_t* tzOffset) { return 0; } +int32_t offsetOfTimezone(char* tzStr, int64_t* offset) { + return parseTimezone(tzStr, offset); +} + /* * rfc3339 format: * 2013-04-12T15:52:01+08:00 diff --git a/source/libs/scalar/src/sclfunc.c b/source/libs/scalar/src/sclfunc.c index e7c6297f44..6144ebd340 100644 --- a/source/libs/scalar/src/sclfunc.c +++ b/source/libs/scalar/src/sclfunc.c @@ -1083,6 +1083,15 @@ int32_t toISO8601Function(SScalarParam *pInput, int32_t inputNum, SScalarParam * memmove(fraction, fraction + TSDB_TIME_PRECISION_SEC_DIGITS, TSDB_TIME_PRECISION_SEC_DIGITS); } + // trans current timezone's unix ts to dest timezone + // offset = delta from dest timezone to zero + // delta from zero to current timezone = 3600 * (cur)tsTimezone + int64_t offset = 0; + if (0 != offsetOfTimezone(tz, &offset)) { + goto _end; + } + timeVal -= offset + 3600 * ((int64_t)tsTimezone); + struct tm tmInfo; int32_t len = 0;