Skip to content

Commit 1b37bab

Browse files
authored
Remove unnecessary % in ToFourDigitYear (#78728)
From previous checks we know year >= 0 && year < 100, so year % 100 == year.
1 parent 89cfbfd commit 1b37bab

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/libraries/System.Private.CoreLib/src/System/Globalization/GregorianCalendarHelper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,8 +533,7 @@ public int ToFourDigitYear(int year, int twoDigitYearMax)
533533

534534
if (year < 100)
535535
{
536-
int y = year % 100;
537-
return (twoDigitYearMax / 100 - (y > twoDigitYearMax % 100 ? 1 : 0)) * 100 + y;
536+
return (twoDigitYearMax / 100 - (year > twoDigitYearMax % 100 ? 1 : 0)) * 100 + year;
538537
}
539538

540539
if (year < m_minYear || year > m_maxYear)
@@ -543,6 +542,7 @@ public int ToFourDigitYear(int year, int twoDigitYearMax)
543542
nameof(year),
544543
SR.Format(SR.ArgumentOutOfRange_Range, m_minYear, m_maxYear));
545544
}
545+
546546
// If the year value is above 100, just return the year value. Don't have to do
547547
// the TwoDigitYearMax comparison.
548548
return year;

0 commit comments

Comments
 (0)