diff options
author | Stephen Toub <stoub@microsoft.com> | 2017-09-08 09:57:55 -0400 |
---|---|---|
committer | Stephen Toub <stoub@microsoft.com> | 2017-10-06 08:27:41 -0400 |
commit | 63829851715ecf694bbdb07bc5677d6df83a4b15 (patch) | |
tree | 5d8ac9432b3cfc117405b395177c21be81a65697 /src | |
parent | 89a825e4a74445bdf29b9114a209ed45f16ddc79 (diff) | |
download | coreclr-63829851715ecf694bbdb07bc5677d6df83a4b15.tar.gz coreclr-63829851715ecf694bbdb07bc5677d6df83a4b15.tar.bz2 coreclr-63829851715ecf694bbdb07bc5677d6df83a4b15.zip |
Add IsValidYear/Day overrides to GregorianCalendar
The base implementation makes several virtual calls that the derived implementation can avoid.
Diffstat (limited to 'src')
-rw-r--r-- | src/mscorlib/shared/System/Globalization/GregorianCalendar.cs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/mscorlib/shared/System/Globalization/GregorianCalendar.cs b/src/mscorlib/shared/System/Globalization/GregorianCalendar.cs index 81058ff664..16023209ea 100644 --- a/src/mscorlib/shared/System/Globalization/GregorianCalendar.cs +++ b/src/mscorlib/shared/System/Globalization/GregorianCalendar.cs @@ -382,6 +382,22 @@ namespace System.Globalization return time.Year; } + internal override bool IsValidYear(int year, int era) => year >= 1 && year <= MaxYear; + + internal override bool IsValidDay(int year, int month, int day, int era) + { + if ((era != CurrentEra && era != ADEra) || + year < 1 || year > MaxYear || + month < 1 || month > 12 || + day < 1) + { + return false; + } + + int[] days = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) ? DaysToMonth366 : DaysToMonth365; + return day <= (days[month] - days[month - 1]); + } + // Checks whether a given day in the specified era is a leap day. This method returns true if // the date is a leap day, or false if not. // |