From 63829851715ecf694bbdb07bc5677d6df83a4b15 Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Fri, 8 Sep 2017 09:57:55 -0400 Subject: [PATCH] Add IsValidYear/Day overrides to GregorianCalendar The base implementation makes several virtual calls that the derived implementation can avoid. --- .../shared/System/Globalization/GregorianCalendar.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/mscorlib/shared/System/Globalization/GregorianCalendar.cs b/src/mscorlib/shared/System/Globalization/GregorianCalendar.cs index 81058ff..1602320 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. // -- 2.7.4