增加手动设置时区的功能

This commit is contained in:
Meco Man 2021-05-01 05:51:18 +08:00
parent 79a452b26d
commit a7a3ca9f02
2 changed files with 9 additions and 3 deletions

View File

@ -55,8 +55,14 @@ endif
if RT_USING_LIBC != y
config RT_LIBC_USING_TIME
bool "Enable TIME FUNCTIONS WITHOUT COMPILER'S LIBC"
bool "Enable time functions without compiler's libc"
default y
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

View File

@ -214,7 +214,7 @@ struct tm* localtime_r(const time_t* t, struct tm* r)
time_t local_tz;
int utc_plus;
utc_plus = 8; /* GMT: UTC+8 */
utc_plus = RT_LIBC_FIXED_TIMEZONE;
local_tz = *t + utc_plus * 3600;
return gmtime_r(&local_tz, r);
}
@ -233,7 +233,7 @@ time_t mktime(struct tm * const t)
time_t timestamp;
int utc_plus;
utc_plus = 8; /* GMT: UTC+8 */
utc_plus = RT_LIBC_FIXED_TIMEZONE;
timestamp = timegm(t);
timestamp = timestamp - 3600 * utc_plus;
return timestamp;