未验证 提交 be3b5a95 编写于 作者: B Bernard Xiong 提交者: GitHub

Merge pull request #4653 from mysterywolf/fixed-timezone

[libc][time]增加手动设置固定时区的功能
...@@ -55,8 +55,14 @@ endif ...@@ -55,8 +55,14 @@ endif
if RT_USING_LIBC != y if RT_USING_LIBC != y
config RT_LIBC_USING_TIME config RT_LIBC_USING_TIME
bool "Enable TIME FUNCTIONS WITHOUT COMPILER'S LIBC" bool "Enable time functions without compiler's libc"
default y default y
endif endif
config RT_LIBC_FIXED_TIMEZONE
depends on (RT_LIBC_USING_TIME || RT_USING_LIBC)
int "Manually set a fixed time zone (UTC+)"
range -12 12
default 8
endmenu endmenu
...@@ -30,6 +30,10 @@ ...@@ -30,6 +30,10 @@
#define DBG_LVL DBG_INFO #define DBG_LVL DBG_INFO
#include <rtdbg.h> #include <rtdbg.h>
#ifndef RT_LIBC_FIXED_TIMEZONE
#define RT_LIBC_FIXED_TIMEZONE 8 /* UTC+8 */
#endif
/* seconds per day */ /* seconds per day */
#define SPD 24*60*60 #define SPD 24*60*60
...@@ -208,14 +212,11 @@ struct tm* gmtime(const time_t* t) ...@@ -208,14 +212,11 @@ struct tm* gmtime(const time_t* t)
} }
RTM_EXPORT(gmtime); RTM_EXPORT(gmtime);
/*TODO: timezone */
struct tm* localtime_r(const time_t* t, struct tm* r) struct tm* localtime_r(const time_t* t, struct tm* r)
{ {
time_t local_tz; time_t local_tz;
int utc_plus;
utc_plus = 8; /* GMT: UTC+8 */ local_tz = *t + RT_LIBC_FIXED_TIMEZONE * 3600;
local_tz = *t + utc_plus * 3600;
return gmtime_r(&local_tz, r); return gmtime_r(&local_tz, r);
} }
RTM_EXPORT(localtime_r); RTM_EXPORT(localtime_r);
...@@ -227,15 +228,12 @@ struct tm* localtime(const time_t* t) ...@@ -227,15 +228,12 @@ struct tm* localtime(const time_t* t)
} }
RTM_EXPORT(localtime); RTM_EXPORT(localtime);
/* TODO: timezone */
time_t mktime(struct tm * const t) time_t mktime(struct tm * const t)
{ {
time_t timestamp; time_t timestamp;
int utc_plus;
utc_plus = 8; /* GMT: UTC+8 */
timestamp = timegm(t); timestamp = timegm(t);
timestamp = timestamp - 3600 * utc_plus; timestamp = timestamp - 3600 * RT_LIBC_FIXED_TIMEZONE;
return timestamp; return timestamp;
} }
RTM_EXPORT(mktime); RTM_EXPORT(mktime);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册