summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormilo <[email protected]>2026-01-16 22:29:25 +0800
committerMeco Man <[email protected]>2026-01-17 19:12:40 -0500
commit3ca5cd53f53d036604d663ac988aeb778bc52813 (patch)
tree2d288461b3edbdd7595c9097557ff3ee56bbedab
parent9bf3a54191587777269daf39b3f7bd7fc9f0067a (diff)
[fix] fix normalization issue of mktime and timegm
-rw-r--r--components/libc/compilers/common/ctime.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/components/libc/compilers/common/ctime.c b/components/libc/compilers/common/ctime.c
index 159667bbcf..bcd19fc8aa 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;