fix toISO8601Function

This commit is contained in:
Bob Liu 2023-11-12 19:15:41 +08:00
parent 08d9277113
commit ba8a410d6d
3 changed files with 20 additions and 0 deletions

View File

@ -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

View File

@ -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

View File

@ -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;