private ParseResult <LocalDate> DetermineMonth(PatternFields usedFields) { switch (usedFields & (PatternFields.MonthOfYearNumeric | PatternFields.MonthOfYearText)) { case PatternFields.MonthOfYearNumeric: // No-op break; case PatternFields.MonthOfYearText: MonthOfYearNumeric = MonthOfYearText; break; case PatternFields.MonthOfYearNumeric | PatternFields.MonthOfYearText: if (MonthOfYearNumeric != MonthOfYearText) { return(ParseResult <LocalDate> .InconsistentMonthValues); } // No need to change MonthOfYearNumeric - this was just a check break; case 0: MonthOfYearNumeric = templateValue.Month; break; } if (MonthOfYearNumeric > Calendar.GetMaxMonth(Year)) { return(ParseResult <LocalDate> .MonthOutOfRange(MonthOfYearNumeric, Year)); } return(null); }
public void MaxDate(CalendarSystem calendar) { // Construct the largest LocalDate we can, and validate that all the properties can be fetched without // issues. int year = calendar.MaxYear; int month = calendar.GetMaxMonth(year); int day = calendar.GetDaysInMonth(year, month); ValidateProperties(year, month, day, calendar); }
/// <summary> /// Converts each day in a full leap cycle (for coverage of different scenarios) to the ISO /// calendar and back. This exercises fetching the number of days since the epoch and getting /// a year/month/day *from* a number of days. /// </summary> private static void TestLeapCycle(CalendarSystem calendar) { for (int year = 5400; year < 5419; year++) { #if !V1 int maxMonth = calendar.GetMonthsInYear(year); #else int maxMonth = calendar.GetMaxMonth(year); #endif for (int month = 1; month <= maxMonth; month++) { int maxDay = calendar.GetDaysInMonth(year, month); for (int day = 1; day <= maxDay; day++) { var date = new LocalDate(year, month, day, calendar); date.WithCalendar(CalendarSystem.Iso).WithCalendar(calendar).Consume(); } } } }