浏览代码

增加手动设置时区的功能

Meco Man 4 年之前
父节点
当前提交
a7a3ca9f02
共有 2 个文件被更改,包括 9 次插入3 次删除
  1. 7 1
      components/libc/Kconfig
  2. 2 2
      components/libc/compilers/common/time.c

+ 7 - 1
components/libc/Kconfig

@@ -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

+ 2 - 2
components/libc/compilers/common/time.c

@@ -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;