Skip to content

Commit 3ca5cd5

Browse files
milo-9mysterywolf
authored andcommitted
[fix] fix normalization issue of mktime and timegm
1 parent 9bf3a54 commit 3ca5cd5

File tree

1 file changed

+2
-1
lines changed
  • components/libc/compilers/common

1 file changed

+2
-1
lines changed

components/libc/compilers/common/ctime.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,6 @@ time_t timegm(struct tm * const t)
391391
return (time_t)-1;
392392
}
393393

394-
years = (time_t)t->tm_year - 70;
395394
if (t->tm_sec > 60) /* seconds after the minute - [0, 60] including leap second */
396395
{
397396
t->tm_min += t->tm_sec / 60;
@@ -433,6 +432,8 @@ time_t timegm(struct tm * const t)
433432
return (time_t) -1;
434433
}
435434

435+
years = (time_t)t->tm_year - 70;
436+
436437
/* Days since 1970 is 365 * number of years + number of leap years since 1970 */
437438
day = years * 365 + (years + 1) / 4;
438439

0 commit comments

Comments
 (0)