ucrtbase: Consolidate strftime code for formats %g %G %V.

Signed-off-by: Jeff Smith <whydoubt@gmail.com>
Signed-off-by: Piotr Caban <piotr@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Jeff Smith 2019-11-27 17:52:37 +01:00 committed by Alexandre Julliard
parent 4f5342fff0
commit 251ef88e01
1 changed files with 11 additions and 18 deletions

View File

@ -1325,24 +1325,9 @@ static MSVCRT_size_t strftime_impl(STRFTIME_CHAR *str, MSVCRT_size_t max,
break; break;
case 'g': case 'g':
case 'G': case 'G':
{
int iso_year = year;
if(!MSVCRT_CHECK_PMT(year>=0 && year<=9999)) if(!MSVCRT_CHECK_PMT(year>=0 && year<=9999))
goto einval_error; goto einval_error;
if (mstm->tm_yday - (mstm->tm_wday ? mstm->tm_wday : 7) + 4 < 0) /* fall through */
iso_year--;
else if(mstm->tm_yday - (mstm->tm_wday ? mstm->tm_wday : 7) + 5 > 365 + IsLeapYear(iso_year))
iso_year++;
if(*format == 'G')
{
if (!strftime_int(str, &ret, max, iso_year, 4, 0, 9999))
return 0;
} else {
if (!strftime_int(str, &ret, max, iso_year%100, 2, 0, 99))
return 0;
}
break;
}
case 'V': case 'V':
{ {
int iso_year = year; int iso_year = year;
@ -1352,8 +1337,16 @@ static MSVCRT_size_t strftime_impl(STRFTIME_CHAR *str, MSVCRT_size_t max,
else if(iso_days >= 365 + IsLeapYear(iso_year)) else if(iso_days >= 365 + IsLeapYear(iso_year))
iso_days -= 365 + IsLeapYear(iso_year++); iso_days -= 365 + IsLeapYear(iso_year++);
if(!strftime_int(str, &ret, max, iso_days/7 + 1, alternate ? 0 : 2, 0, 53)) if(*format == 'G') {
return 0; if(!strftime_int(str, &ret, max, iso_year, 4, 0, 9999))
return 0;
} else if(*format == 'g') {
if(!strftime_int(str, &ret, max, iso_year%100, 2, 0, 99))
return 0;
} else {
if(!strftime_int(str, &ret, max, iso_days/7 + 1, alternate ? 0 : 2, 0, 53))
return 0;
}
break; break;
} }
#endif #endif