From 51c9a6fac77b0f42404f950098bc47784859676b Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Wed, 8 Jun 2022 22:42:10 +0800 Subject: [PATCH] fix(query): fix to_iso8601 function append format in "-hh:mm", "-hhmm" "-hh", "z" when digits exceeds 10 digits --- source/libs/scalar/src/sclfunc.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/source/libs/scalar/src/sclfunc.c b/source/libs/scalar/src/sclfunc.c index 2b15f5031e..2369779105 100644 --- a/source/libs/scalar/src/sclfunc.c +++ b/source/libs/scalar/src/sclfunc.c @@ -901,12 +901,22 @@ int32_t toISO8601Function(SScalarParam *pInput, int32_t inputNum, SScalarParam * if (hasFraction) { int32_t fracLen = (int32_t)strlen(fraction) + 1; - char *tzInfo = strchr(buf, '+'); - if (tzInfo) { + + char *tzInfo; + if (buf[len - 1] == 'z' || buf[len - 1] == 'Z') { + tzInfo = &buf[len - 1]; memmove(tzInfo + fracLen, tzInfo, strlen(tzInfo)); } else { - tzInfo = strchr(buf, '-'); - memmove(tzInfo + fracLen, tzInfo, strlen(tzInfo)); + tzInfo = strchr(buf, '+'); + if (tzInfo) { + memmove(tzInfo + fracLen, tzInfo, strlen(tzInfo)); + } else { + //search '-' backwards + tzInfo = strrchr(buf, '-'); + if (tzInfo) { + memmove(tzInfo + fracLen, tzInfo, strlen(tzInfo)); + } + } } char tmp[32] = {0}; -- GitLab