فهرست منبع

[fix] fix normalization issue of mktime and timegm

milo 1 روز پیش
والد
کامیت
3ca5cd53f5
1فایلهای تغییر یافته به همراه2 افزوده شده و 1 حذف شده
  1. 2 1
      components/libc/compilers/common/ctime.c

+ 2 - 1
components/libc/compilers/common/ctime.c

@@ -391,7 +391,6 @@ time_t timegm(struct tm * const t)
         return (time_t)-1;
         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 */
     if (t->tm_sec > 60)         /* seconds after the minute - [0, 60] including leap second */
     {
     {
         t->tm_min += t->tm_sec / 60;
         t->tm_min += t->tm_sec / 60;
@@ -433,6 +432,8 @@ time_t timegm(struct tm * const t)
         return (time_t) -1;
         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 */
     /* Days since 1970 is 365 * number of years + number of leap years since 1970 */
     day = years * 365 + (years + 1) / 4;
     day = years * 365 + (years + 1) / 4;