From 6e8f399e153f2c9ed2f3da779f6e6b757dade22e Mon Sep 17 00:00:00 2001 From: milo <1569491816@qq.com> Date: Fri, 16 Jan 2026 22:29:25 +0800 Subject: [PATCH] [fix] fix normalization issue of mktime and timegm --- components/libc/compilers/common/ctime.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/components/libc/compilers/common/ctime.c b/components/libc/compilers/common/ctime.c index 159667bbcfa..bcd19fc8aad 100644 --- a/components/libc/compilers/common/ctime.c +++ b/components/libc/compilers/common/ctime.c @@ -391,7 +391,6 @@ time_t timegm(struct tm * const t) return (time_t)-1; } - years = (time_t)t->tm_year - 70; if (t->tm_sec > 60) /* seconds after the minute - [0, 60] including leap second */ { t->tm_min += t->tm_sec / 60; @@ -433,6 +432,8 @@ time_t timegm(struct tm * const t) return (time_t) -1; } + years = (time_t)t->tm_year - 70; + /* Days since 1970 is 365 * number of years + number of leap years since 1970 */ day = years * 365 + (years + 1) / 4;