Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
b190be6f
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看板
提交
b190be6f
编写于
1月 19, 2021
作者:
D
dapan1121
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix bug
上级
ee5e9a71
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
51 addition
and
17 deletion
+51
-17
src/os/src/detail/osTime.c
src/os/src/detail/osTime.c
+51
-17
未找到文件。
src/os/src/detail/osTime.c
浏览文件 @
b190be6f
...
...
@@ -20,6 +20,7 @@
#include "os.h"
#include "taosdef.h"
#include "tutil.h"
#include "tulog.h"
/*
* mktime64 - Converts date to seconds.
...
...
@@ -457,6 +458,13 @@ int64_t taosTimeTruncate(int64_t t, const SInterval* pInterval, int32_t precisio
return
t
;
}
#if defined(WINDOWS) && _MSC_VER >= 1900
// see https://docs.microsoft.com/en-us/cpp/c-runtime-library/daylight-dstbias-timezone-and-tzname?view=vs-2019
int64_t
timezone
=
_timezone
;
int32_t
daylight
=
_daylight
;
char
**
tzname
=
_tzname
;
#endif
int64_t
start
=
t
;
if
(
pInterval
->
slidingUnit
==
'n'
||
pInterval
->
slidingUnit
==
'y'
)
{
start
/=
(
int64_t
)(
TSDB_TICK_PER_SECOND
(
precision
));
...
...
@@ -479,15 +487,26 @@ int64_t taosTimeTruncate(int64_t t, const SInterval* pInterval, int32_t precisio
}
start
=
(
int64_t
)(
mktime
(
&
tm
)
*
TSDB_TICK_PER_SECOND
(
precision
));
#if defined(WINDOWS) && _MSC_VER >= 1900
// see https://docs.microsoft.com/en-us/cpp/c-runtime-library/daylight-dstbias-timezone-and-tzname?view=vs-2019
int64_t
timezone
=
_timezone
;
int32_t
daylight
=
_daylight
;
char
**
tzname
=
_tzname
;
#endif
assert
(
pInterval
->
tz
%
3600
==
0
);
start
-=
(
timezone
-
pInterval
->
tz
)
*
TSDB_TICK_PER_SECOND
(
precision
);
if
(
start
>
t
)
{
if
(
pInterval
->
slidingUnit
==
'y'
)
{
tm
.
tm_mon
=
0
;
tm
.
tm_year
--
;
}
else
{
tm
.
tm_mon
--
;
int
mon
=
tm
.
tm_year
*
12
+
tm
.
tm_mon
;
mon
=
(
int
)(
mon
/
pInterval
->
sliding
*
pInterval
->
sliding
);
tm
.
tm_year
=
mon
/
12
;
tm
.
tm_mon
=
mon
%
12
;
}
start
=
(
int64_t
)(
mktime
(
&
tm
)
*
TSDB_TICK_PER_SECOND
(
precision
));
start
-=
(
timezone
-
pInterval
->
tz
)
*
TSDB_TICK_PER_SECOND
(
precision
);
}
}
else
{
int64_t
delta
=
t
-
pInterval
->
interval
;
int32_t
factor
=
(
delta
>=
0
)
?
1
:
-
1
;
...
...
@@ -499,28 +518,27 @@ int64_t taosTimeTruncate(int64_t t, const SInterval* pInterval, int32_t precisio
* here we revised the start time of day according to the local time zone,
* but in case of DST, the start time of one day need to be dynamically decided.
*/
// todo refactor to extract function that is available for Linux/Windows/Mac platform
#if defined(WINDOWS) && _MSC_VER >= 1900
// see https://docs.microsoft.com/en-us/cpp/c-runtime-library/daylight-dstbias-timezone-and-tzname?view=vs-2019
int64_t
timezone
=
_timezone
;
int32_t
daylight
=
_daylight
;
char
**
tzname
=
_tzname
;
#endif
assert
(
pInterval
->
tz
%
3600
==
0
);
start
+=
(
int64_t
)(
pInterval
->
tz
*
TSDB_TICK_PER_SECOND
(
precision
));
if
(
start
>
t
)
{
start
-=
(
int64_t
)(
pInterval
->
tz
*
TSDB_TICK_PER_SECOND
(
precision
));
start
=
(
delta
/
pInterval
->
sliding
-
1
)
*
pInterval
->
sliding
;
}
}
int64_t
end
=
0
;
// not enough time range
if
(
INT64_MAX
-
start
>
pInterval
->
interval
-
1
)
{
if
(
start
<
0
||
INT64_MAX
-
start
>
pInterval
->
interval
-
1
)
{
end
=
start
+
pInterval
->
interval
-
1
;
while
(
end
<
t
&&
((
start
+
pInterval
->
sliding
)
<=
INT64_MAX
))
{
// move forward to the correct time window
start
+=
pInterval
->
sliding
;
if
(
INT64_MAX
-
start
>
pInterval
->
interval
-
1
)
{
if
(
start
<
0
||
INT64_MAX
-
start
>
pInterval
->
interval
-
1
)
{
end
=
start
+
pInterval
->
interval
-
1
;
}
else
{
end
=
INT64_MAX
;
...
...
@@ -538,6 +556,22 @@ int64_t taosTimeTruncate(int64_t t, const SInterval* pInterval, int32_t precisio
start
=
taosTimeAdd
(
start
,
-
pInterval
->
interval
,
pInterval
->
intervalUnit
,
precision
);
}
}
/*
struct tm tm;
time_t tt = (time_t)start/(int64_t)(TSDB_TICK_PER_SECOND(precision));
localtime_r(&tt, &tm);
uError("origin start:%" PRId64 ", final start:%" PRId64 ",in tz:%" PRId64 ",local tz:%" PRId64 ",interval:%" PRId64 "%c,sliding:%" PRId64 "%c,y:%d,m:%d,d:%d,h:%d,m:%d,s:%d",
t, start, pInterval->tz, timezone, pInterval->interval, pInterval->intervalUnit, pInterval->sliding, pInterval->slidingUnit,
tm.tm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
*/
return
start
;
}
...
...
@@ -584,4 +618,4 @@ const char* fmtts(int64_t ts) {
}
return
buf
;
}
\ No newline at end of file
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录