Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
bf53345f
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
bf53345f
编写于
4月 11, 2023
作者:
X
xinsheng Ren
提交者:
GitHub
4月 11, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: windows gettime negative value (#20800)
上级
9b6f4e34
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
92 addition
and
18 deletion
+92
-18
source/os/src/osTime.c
source/os/src/osTime.c
+15
-18
source/os/test/osTimeTests.cpp
source/os/test/osTimeTests.cpp
+77
-0
未找到文件。
source/os/src/osTime.c
浏览文件 @
bf53345f
...
...
@@ -37,6 +37,9 @@
// This magic number is the number of 100 nanosecond intervals since January 1, 1601 (UTC)
// until 00:00:00 January 1, 1970
static
const
uint64_t
TIMEEPOCH
=
((
uint64_t
)
116444736000000000ULL
);
// This magic number is the number of 100 nanosecond intervals since January 1, 1601 (UTC)
// until 00:00:00 January 1, 1900
static
const
uint64_t
TIMEEPOCH1900
=
((
uint64_t
)
116445024000000000ULL
);
/*
* We do not implement alternate representations. However, we always
...
...
@@ -409,7 +412,9 @@ time_t taosMktime(struct tm *timep) {
struct
tm
*
taosLocalTime
(
const
time_t
*
timep
,
struct
tm
*
result
,
char
*
buf
)
{
struct
tm
*
res
=
NULL
;
if
(
timep
==
NULL
)
{
return
NULL
;
}
if
(
result
==
NULL
)
{
res
=
localtime
(
timep
);
if
(
res
==
NULL
&&
buf
!=
NULL
)
{
...
...
@@ -419,13 +424,15 @@ struct tm *taosLocalTime(const time_t *timep, struct tm *result, char *buf) {
}
#ifdef WINDOWS
if
(
*
timep
<
0
)
{
if
(
*
timep
<
-
2208988800LL
)
{
if
(
buf
!=
NULL
)
{
sprintf
(
buf
,
"NaN"
);
}
return
NULL
;
// TODO: bugs in following code
SYSTEMTIME
ss
,
s
;
FILETIME
ff
,
f
;
}
SYSTEMTIME
s
;
FILETIME
f
;
LARGE_INTEGER
offset
;
struct
tm
tm1
;
time_t
tt
=
0
;
...
...
@@ -435,17 +442,7 @@ struct tm *taosLocalTime(const time_t *timep, struct tm *result, char *buf) {
}
return
NULL
;
}
ss
.
wYear
=
tm1
.
tm_year
+
1900
;
ss
.
wMonth
=
tm1
.
tm_mon
+
1
;
ss
.
wDay
=
tm1
.
tm_mday
;
ss
.
wHour
=
tm1
.
tm_hour
;
ss
.
wMinute
=
tm1
.
tm_min
;
ss
.
wSecond
=
tm1
.
tm_sec
;
ss
.
wMilliseconds
=
0
;
SystemTimeToFileTime
(
&
ss
,
&
ff
);
offset
.
QuadPart
=
ff
.
dwHighDateTime
;
offset
.
QuadPart
<<=
32
;
offset
.
QuadPart
|=
ff
.
dwLowDateTime
;
offset
.
QuadPart
=
TIMEEPOCH1900
;
offset
.
QuadPart
+=
*
timep
*
10000000
;
f
.
dwLowDateTime
=
offset
.
QuadPart
&
0xffffffff
;
f
.
dwHighDateTime
=
(
offset
.
QuadPart
>>
32
)
&
0xffffffff
;
...
...
source/os/test/osTimeTests.cpp
浏览文件 @
bf53345f
...
...
@@ -46,3 +46,80 @@ TEST(osTimeTests, taosLocalTimeNolock) {
EXPECT_EQ
(
expectedTime
.
tm_yday
,
result
->
tm_yday
);
EXPECT_EQ
(
expectedTime
.
tm_isdst
,
result
->
tm_isdst
);
}
TEST
(
osTimeTests
,
taosLocalTime
)
{
// Test 1: Test when both timep and result are not NULL
time_t
timep
=
1617531000
;
// 2021-04-04 18:10:00
struct
tm
result
;
struct
tm
*
local_time
=
taosLocalTime
(
&
timep
,
&
result
,
NULL
);
ASSERT_NE
(
local_time
,
nullptr
);
ASSERT_EQ
(
local_time
->
tm_year
,
121
);
ASSERT_EQ
(
local_time
->
tm_mon
,
3
);
ASSERT_EQ
(
local_time
->
tm_mday
,
4
);
ASSERT_EQ
(
local_time
->
tm_hour
,
18
);
ASSERT_EQ
(
local_time
->
tm_min
,
10
);
ASSERT_EQ
(
local_time
->
tm_sec
,
00
);
// Test 2: Test when timep is NULL
local_time
=
taosLocalTime
(
NULL
,
&
result
,
NULL
);
ASSERT_EQ
(
local_time
,
nullptr
);
// Test 3: Test when result is NULL
local_time
=
taosLocalTime
(
&
timep
,
NULL
,
NULL
);
ASSERT_NE
(
local_time
,
nullptr
);
ASSERT_EQ
(
local_time
->
tm_year
,
121
);
ASSERT_EQ
(
local_time
->
tm_mon
,
3
);
ASSERT_EQ
(
local_time
->
tm_mday
,
4
);
// Test 4: Test when timep is negative on Windows
#ifdef WINDOWS
time_t
pos_timep
=
1609459200
;
// 2021-01-01 08:00:00
local_time
=
taosLocalTime
(
&
pos_timep
,
&
result
,
NULL
);
ASSERT_NE
(
local_time
,
nullptr
);
ASSERT_EQ
(
local_time
->
tm_year
,
121
);
ASSERT_EQ
(
local_time
->
tm_mon
,
0
);
ASSERT_EQ
(
local_time
->
tm_mday
,
1
);
ASSERT_EQ
(
local_time
->
tm_hour
,
8
);
ASSERT_EQ
(
local_time
->
tm_min
,
0
);
ASSERT_EQ
(
local_time
->
tm_sec
,
0
);
time_t
neg_timep
=
-
1617531000
;
// 1918-09-29 21:50:00
local_time
=
taosLocalTime
(
&
neg_timep
,
&
result
,
NULL
);
ASSERT_NE
(
local_time
,
nullptr
);
ASSERT_EQ
(
local_time
->
tm_year
,
18
);
ASSERT_EQ
(
local_time
->
tm_mon
,
8
);
ASSERT_EQ
(
local_time
->
tm_mday
,
29
);
ASSERT_EQ
(
local_time
->
tm_hour
,
21
);
ASSERT_EQ
(
local_time
->
tm_min
,
50
);
ASSERT_EQ
(
local_time
->
tm_sec
,
0
);
time_t
neg_timep2
=
-
315619200
;
// 1960-01-01 08:00:00
local_time
=
taosLocalTime
(
&
neg_timep2
,
&
result
,
NULL
);
ASSERT_NE
(
local_time
,
nullptr
);
ASSERT_EQ
(
local_time
->
tm_year
,
60
);
ASSERT_EQ
(
local_time
->
tm_mon
,
0
);
ASSERT_EQ
(
local_time
->
tm_mday
,
1
);
ASSERT_EQ
(
local_time
->
tm_hour
,
8
);
ASSERT_EQ
(
local_time
->
tm_min
,
0
);
ASSERT_EQ
(
local_time
->
tm_sec
,
0
);
time_t
zero_timep
=
0
;
// 1970-01-01 08:00:00
local_time
=
taosLocalTime
(
&
zero_timep
,
&
result
,
NULL
);
ASSERT_NE
(
local_time
,
nullptr
);
ASSERT_EQ
(
local_time
->
tm_year
,
70
);
ASSERT_EQ
(
local_time
->
tm_mon
,
0
);
ASSERT_EQ
(
local_time
->
tm_mday
,
1
);
ASSERT_EQ
(
local_time
->
tm_hour
,
8
);
ASSERT_EQ
(
local_time
->
tm_min
,
0
);
ASSERT_EQ
(
local_time
->
tm_sec
,
0
);
time_t
over_timep
=
6406301441633558
;
local_time
=
taosLocalTime
(
&
over_timep
,
&
result
,
NULL
);
ASSERT_EQ
(
local_time
,
nullptr
);
time_t
neg_timep3
=
-
78115158887
;
local_time
=
taosLocalTime
(
&
neg_timep3
,
&
result
,
NULL
);
ASSERT_EQ
(
local_time
,
nullptr
);
#endif
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录