!117 修正tm_gmtoff字段的含义

Merge pull request !117 from Caoruihong/gmtoff
This commit is contained in:
openharmony_ci 2021-05-11 09:47:40 +08:00 committed by Gitee
commit bb90e629cb
1 changed files with 5 additions and 5 deletions

View File

@ -485,7 +485,7 @@ static INT32 ConvertSecs2Utc(time_t t, INT32 offset, struct tm *tp)
days -= daysInMonth[month]; days -= daysInMonth[month];
tp->tm_mon = month; tp->tm_mon = month;
tp->tm_mday = days + 1; tp->tm_mday = days + 1;
tp->__tm_gmtoff = -offset; tp->__tm_gmtoff = offset;
tp->__tm_zone = NULL; tp->__tm_zone = NULL;
tp->tm_isdst = 0; tp->tm_isdst = 0;
return 1; return 1;
@ -557,7 +557,7 @@ static time_t ConvertUtc2Secs(struct tm *tm)
seconds += (tm->tm_mday - 1) * SECS_PER_DAY; seconds += (tm->tm_mday - 1) * SECS_PER_DAY;
seconds += tm->tm_hour * SECS_PER_HOUR + tm->tm_min * SECS_PER_MIN + tm->tm_sec; seconds += tm->tm_hour * SECS_PER_HOUR + tm->tm_min * SECS_PER_MIN + tm->tm_sec;
seconds += tm->__tm_gmtoff; // add time zone to get UTC time seconds -= tm->__tm_gmtoff; // sub time zone to get UTC time
return seconds; return seconds;
} }
@ -571,8 +571,8 @@ time_t mktime(struct tm *tmptr)
/* tm_isdst is not supported and is ignored */ /* tm_isdst is not supported and is ignored */
if (tmptr->tm_year < (EPOCH_YEAR - TM_YEAR_BASE) || if (tmptr->tm_year < (EPOCH_YEAR - TM_YEAR_BASE) ||
tmptr->__tm_gmtoff > (TIME_ZONE_MAX * SECS_PER_MIN) || tmptr->__tm_gmtoff > (-TIME_ZONE_MIN * SECS_PER_MIN) ||
tmptr->__tm_gmtoff < (TIME_ZONE_MIN * SECS_PER_MIN) || tmptr->__tm_gmtoff < (-TIME_ZONE_MAX * SECS_PER_MIN) ||
tmptr->tm_sec > 60 || tmptr->tm_sec < 0 || /* Seconds [0-60] */ tmptr->tm_sec > 60 || tmptr->tm_sec < 0 || /* Seconds [0-60] */
tmptr->tm_min > 59 || tmptr->tm_min < 0 || /* Minutes [0-59] */ tmptr->tm_min > 59 || tmptr->tm_min < 0 || /* Minutes [0-59] */
tmptr->tm_hour > 23 || tmptr->tm_hour < 0 || /* Hours [0-23] */ tmptr->tm_hour > 23 || tmptr->tm_hour < 0 || /* Hours [0-23] */
@ -583,7 +583,7 @@ time_t mktime(struct tm *tmptr)
} }
timeInSeconds = ConvertUtc2Secs(tmptr); timeInSeconds = ConvertUtc2Secs(tmptr);
/* normalize tm_wday and tm_yday */ /* normalize tm_wday and tm_yday */
ConvertSecs2Utc(timeInSeconds, -tmptr->__tm_gmtoff, tmptr); ConvertSecs2Utc(timeInSeconds, tmptr->__tm_gmtoff, tmptr);
return timeInSeconds; return timeInSeconds;
} }