Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
3cfb2ea9
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
3cfb2ea9
编写于
8月 04, 2021
作者:
G
Ganlin Zhao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-5505]<fix>: if there's no space or 'T' delimiter timezone will also be parsed
上级
879a0349
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
39 addition
and
8 deletion
+39
-8
src/os/src/detail/osTime.c
src/os/src/detail/osTime.c
+15
-8
src/query/tests/unitTest.cpp
src/query/tests/unitTest.cpp
+24
-0
未找到文件。
src/os/src/detail/osTime.c
浏览文件 @
3cfb2ea9
...
@@ -86,6 +86,7 @@ static int32_t parseTimeWithTz(char* timestr, int64_t* time, int32_t timePrec, c
...
@@ -86,6 +86,7 @@ static int32_t parseTimeWithTz(char* timestr, int64_t* time, int32_t timePrec, c
static
int32_t
parseLocaltime
(
char
*
timestr
,
int64_t
*
time
,
int32_t
timePrec
);
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
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
int32_t
(
*
parseLocaltimeFp
[])
(
char
*
timestr
,
int64_t
*
time
,
int32_t
timePrec
)
=
{
static
int32_t
(
*
parseLocaltimeFp
[])
(
char
*
timestr
,
int64_t
*
time
,
int32_t
timePrec
)
=
{
parseLocaltime
,
parseLocaltime
,
...
@@ -96,19 +97,25 @@ int32_t taosGetTimestampSec() { return (int32_t)time(NULL); }
...
@@ -96,19 +97,25 @@ 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 */
char
*
seg
=
forwardToTimeStringEnd
(
timestr
);
int32_t
seg_len
=
len
-
(
int32_t
)(
seg
-
timestr
);
if
(
strnchr
(
timestr
,
'T'
,
len
,
false
)
!=
NULL
)
{
if
(
strnchr
(
timestr
,
'T'
,
len
,
false
)
!=
NULL
)
{
return
parseTimeWithTz
(
timestr
,
time
,
timePrec
,
'T'
);
return
parseTimeWithTz
(
timestr
,
time
,
timePrec
,
'T'
);
}
else
if
(
strnchr
(
timestr
,
' '
,
len
,
false
)
!=
NULL
&&
}
else
if
(
checkTzPresent
(
timestr
,
len
))
{
(
strnchr
(
seg
,
'Z'
,
seg_len
,
false
)
!=
NULL
||
strnchr
(
seg
,
'z'
,
seg_len
,
false
)
!=
NULL
||
return
parseTimeWithTz
(
timestr
,
time
,
timePrec
,
0
);
strnchr
(
seg
,
'+'
,
seg_len
,
false
)
!=
NULL
||
strnchr
(
seg
,
'-'
,
seg_len
,
false
)
!=
NULL
))
{
return
parseTimeWithTz
(
timestr
,
time
,
timePrec
,
' '
);
}
else
{
}
else
{
return
(
*
parseLocaltimeFp
[
day_light
])(
timestr
,
time
,
timePrec
);
return
(
*
parseLocaltimeFp
[
day_light
])(
timestr
,
time
,
timePrec
);
}
}
}
}
bool
checkTzPresent
(
char
*
str
,
int32_t
len
)
{
char
*
seg
=
forwardToTimeStringEnd
(
str
);
int32_t
seg_len
=
len
-
(
int32_t
)(
seg
-
str
);
return
(
strnchr
(
seg
,
'Z'
,
seg_len
,
false
)
!=
NULL
||
strnchr
(
seg
,
'z'
,
seg_len
,
false
)
!=
NULL
||
strnchr
(
seg
,
'+'
,
seg_len
,
false
)
!=
NULL
||
strnchr
(
seg
,
'-'
,
seg_len
,
false
)
!=
NULL
);
}
char
*
forwardToTimeStringEnd
(
char
*
str
)
{
char
*
forwardToTimeStringEnd
(
char
*
str
)
{
int32_t
i
=
0
;
int32_t
i
=
0
;
int32_t
numOfSep
=
0
;
int32_t
numOfSep
=
0
;
...
@@ -238,8 +245,8 @@ int32_t parseTimeWithTz(char* timestr, int64_t* time, int32_t timePrec, char del
...
@@ -238,8 +245,8 @@ int32_t parseTimeWithTz(char* timestr, int64_t* time, int32_t timePrec, char del
char
*
str
;
char
*
str
;
if
(
delim
==
'T'
)
{
if
(
delim
==
'T'
)
{
str
=
strptime
(
timestr
,
"%Y-%m-%dT%H:%M:%S"
,
&
tm
);
str
=
strptime
(
timestr
,
"%Y-%m-%dT%H:%M:%S"
,
&
tm
);
}
else
if
(
delim
==
' '
)
{
}
else
if
(
delim
==
0
)
{
str
=
strptime
(
timestr
,
"%Y-%m-%d
%n
%H:%M:%S"
,
&
tm
);
str
=
strptime
(
timestr
,
"%Y-%m-%d
%H:%M:%S"
,
&
tm
);
}
else
{
}
else
{
str
=
NULL
;
str
=
NULL
;
}
}
...
...
src/query/tests/unitTest.cpp
浏览文件 @
3cfb2ea9
...
@@ -434,6 +434,29 @@ TEST(testCase, parse_time) {
...
@@ -434,6 +434,29 @@ TEST(testCase, parse_time) {
taosParseTime
(
t64
,
&
time1
,
strlen
(
t64
),
TSDB_TIME_PRECISION_MILLI
,
0
);
taosParseTime
(
t64
,
&
time1
,
strlen
(
t64
),
TSDB_TIME_PRECISION_MILLI
,
0
);
EXPECT_EQ
(
time
,
time1
);
EXPECT_EQ
(
time
,
time1
);
// "%Y-%m-%d%H:%M:%S" format with TimeZone appendix is also treated as legal
// and TimeZone will be processed
char
t80
[]
=
"2017-4-51:1:2.980"
;
char
t81
[]
=
"2017-4-52:1:2.98+9:00"
;
taosParseTime
(
t80
,
&
time
,
strlen
(
t80
),
TSDB_TIME_PRECISION_MILLI
,
0
);
taosParseTime
(
t81
,
&
time1
,
strlen
(
t81
),
TSDB_TIME_PRECISION_MILLI
,
0
);
EXPECT_EQ
(
time
,
time1
);
char
t82
[]
=
"2017-4-52:1:2.98+09:00"
;
taosParseTime
(
t82
,
&
time
,
strlen
(
t82
),
TSDB_TIME_PRECISION_MILLI
,
0
);
taosParseTime
(
t81
,
&
time1
,
strlen
(
t81
),
TSDB_TIME_PRECISION_MILLI
,
0
);
EXPECT_EQ
(
time
,
time1
);
char
t83
[]
=
"2017-4-52:1:2.98+0900"
;
taosParseTime
(
t83
,
&
time
,
strlen
(
t83
),
TSDB_TIME_PRECISION_MILLI
,
0
);
taosParseTime
(
t82
,
&
time1
,
strlen
(
t82
),
TSDB_TIME_PRECISION_MILLI
,
0
);
EXPECT_EQ
(
time
,
time1
);
char
t84
[]
=
"2017-4-417:1:2.98Z"
;
taosParseTime
(
t83
,
&
time
,
strlen
(
t83
),
TSDB_TIME_PRECISION_MILLI
,
0
);
taosParseTime
(
t84
,
&
time1
,
strlen
(
t84
),
TSDB_TIME_PRECISION_MILLI
,
0
);
EXPECT_EQ
(
time
,
time1
);
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
// illegal timestamp format
// illegal timestamp format
char
t15
[]
=
"2017-12-33 0:0:0"
;
char
t15
[]
=
"2017-12-33 0:0:0"
;
...
@@ -498,6 +521,7 @@ TEST(testCase, parse_time) {
...
@@ -498,6 +521,7 @@ TEST(testCase, parse_time) {
char
t70
[]
=
"2017-12-31 9:0:0.123Z+12:00"
;
char
t70
[]
=
"2017-12-31 9:0:0.123Z+12:00"
;
EXPECT_EQ
(
taosParseTime
(
t70
,
&
time
,
strlen
(
t70
),
TSDB_TIME_PRECISION_MILLI
,
0
),
-
1
);
EXPECT_EQ
(
taosParseTime
(
t70
,
&
time
,
strlen
(
t70
),
TSDB_TIME_PRECISION_MILLI
,
0
),
-
1
);
}
}
TEST
(
testCase
,
tvariant_convert
)
{
TEST
(
testCase
,
tvariant_convert
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录