Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wwsmg1
rt-thread
提交
e6467321
R
rt-thread
项目概览
wwsmg1
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rt-thread
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
e6467321
编写于
7月 21, 2021
作者:
B
Bernard Xiong
提交者:
GitHub
7月 21, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #4876 from mysterywolf/tz
[libc][timezone] implement timezone APIs
上级
73bd7a7d
0f48449b
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
42 addition
and
10 deletion
+42
-10
components/libc/Kconfig
components/libc/Kconfig
+2
-2
components/libc/compilers/common/sys/time.h
components/libc/compilers/common/sys/time.h
+7
-0
components/libc/compilers/common/time.c
components/libc/compilers/common/time.c
+33
-8
未找到文件。
components/libc/Kconfig
浏览文件 @
e6467321
...
...
@@ -59,9 +59,9 @@ if RT_USING_LIBC != y
default y
endif
config RT_LIBC_
FIXED
_TIMEZONE
config RT_LIBC_
DEFAULT
_TIMEZONE
depends on (RT_LIBC_USING_TIME || RT_USING_LIBC)
int "
Manually set a fixed
time zone (UTC+)"
int "
Set the default
time zone (UTC+)"
range -12 12
default 8
...
...
components/libc/compilers/common/sys/time.h
浏览文件 @
e6467321
...
...
@@ -12,6 +12,7 @@
#define _SYS_TIME_H_
#include <rtconfig.h>
#include <rtdef.h>
#include <time.h>
#ifdef __cplusplus
...
...
@@ -98,6 +99,12 @@ int clock_settime (clockid_t clockid, const struct timespec *tp);
int
clock_time_to_tick
(
const
struct
timespec
*
time
);
#endif
/* RT_USING_POSIX */
/* timezone APIs (Not standard LIBC APIs) */
void
rt_tz_set
(
rt_int8_t
tz
);
rt_int8_t
rt_tz_get
(
void
);
rt_int8_t
rt_tz_is_dst
(
void
);
#ifdef __cplusplus
}
#endif
...
...
components/libc/compilers/common/time.c
浏览文件 @
e6467321
...
...
@@ -18,6 +18,7 @@
* 2021-02-12 Meco Man move all of the functions located in <clock_time.c> to this file
* 2021-03-15 Meco Man fixed a bug of leaking memory in asctime()
* 2021-05-01 Meco Man support fixed timezone
* 2021-07-21 Meco Man implement that change/set timezone APIs
*/
#include "sys/time.h"
...
...
@@ -32,10 +33,6 @@
#define DBG_LVL DBG_INFO
#include <rtdbg.h>
#ifndef RT_LIBC_FIXED_TIMEZONE
#define RT_LIBC_FIXED_TIMEZONE 8
/* UTC+8 */
#endif
/* seconds per day */
#define SPD 24*60*60
...
...
@@ -202,7 +199,7 @@ struct tm *gmtime_r(const time_t *timep, struct tm *r)
r
->
tm_mon
=
i
;
r
->
tm_mday
+=
work
-
__spm
[
i
];
r
->
tm_isdst
=
0
;
r
->
tm_isdst
=
rt_tz_is_dst
()
;
return
r
;
}
RTM_EXPORT
(
gmtime_r
);
...
...
@@ -218,7 +215,7 @@ struct tm* localtime_r(const time_t* t, struct tm* r)
{
time_t
local_tz
;
local_tz
=
*
t
+
RT_LIBC_FIXED_TIMEZONE
*
3600
;
local_tz
=
*
t
+
rt_tz_get
()
*
3600
;
return
gmtime_r
(
&
local_tz
,
r
);
}
RTM_EXPORT
(
localtime_r
);
...
...
@@ -235,7 +232,7 @@ time_t mktime(struct tm * const t)
time_t
timestamp
;
timestamp
=
timegm
(
t
);
timestamp
=
timestamp
-
3600
*
RT_LIBC_FIXED_TIMEZONE
;
timestamp
=
timestamp
-
3600
*
rt_tz_get
()
;
return
timestamp
;
}
RTM_EXPORT
(
mktime
);
...
...
@@ -426,7 +423,7 @@ int gettimeofday(struct timeval *tv, struct timezone *tz)
if
(
tz
!=
RT_NULL
)
{
tz
->
tz_dsttime
=
DST_NONE
;
tz
->
tz_minuteswest
=
-
(
RT_LIBC_FIXED_TIMEZONE
*
60
);
tz
->
tz_minuteswest
=
-
(
rt_tz_get
()
*
60
);
}
if
(
tv
!=
RT_NULL
&&
get_timeval
(
tv
)
==
RT_EOK
)
...
...
@@ -651,3 +648,31 @@ int clock_time_to_tick(const struct timespec *time)
RTM_EXPORT
(
clock_time_to_tick
);
#endif
/* RT_USING_POSIX */
/* timezone APIs (Not standard LIBC APIs) */
#ifndef RT_LIBC_DEFAULT_TIMEZONE
#define RT_LIBC_DEFAULT_TIMEZONE 8
#endif
#include <rthw.h>
volatile
static
rt_int8_t
rt_current_timezone
=
RT_LIBC_DEFAULT_TIMEZONE
;
void
rt_tz_set
(
rt_int8_t
tz
)
{
register
rt_base_t
level
;
level
=
rt_hw_interrupt_disable
();
rt_current_timezone
=
tz
;
rt_hw_interrupt_enable
(
level
);
}
rt_int8_t
rt_tz_get
(
void
)
{
return
rt_current_timezone
;
}
rt_int8_t
rt_tz_is_dst
(
void
)
{
return
0
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录