private CalendarSystem(CalendarOrdinal ordinal, string id, string name, YearMonthDayCalculator yearMonthDayCalculator, int minDaysInFirstWeek, EraCalculator eraCalculator) { this.Ordinal = ordinal; this.Id = id; this.Name = name; this.YearMonthDayCalculator = yearMonthDayCalculator; this.weekYearCalculator = new WeekYearCalculator(yearMonthDayCalculator, minDaysInFirstWeek); this.MinYear = yearMonthDayCalculator.MinYear; this.MaxYear = yearMonthDayCalculator.MaxYear; this.MinDays = yearMonthDayCalculator.GetStartOfYearInDays(MinYear); this.MaxDays = yearMonthDayCalculator.GetStartOfYearInDays(MaxYear + 1) - 1; // We trust the construction code not to mutate the array... this.eraCalculator = eraCalculator; CalendarByOrdinal[(int) ordinal] = this; }
internal GJEraCalculator(YearMonthDayCalculator ymdCalculator) : base(Era.BeforeCommon, Era.Common) { maxYearOfBc = 1 - ymdCalculator.MinYear; // Convert from absolute to year-of-era maxYearOfAd = ymdCalculator.MaxYear; }
internal SingleEraCalculator(Era era, YearMonthDayCalculator ymdCalculator) : base(era) { minYear = ymdCalculator.MinYear; maxYear = ymdCalculator.MaxYear; this.era = era; }
private CalendarSystem(CalendarOrdinal ordinal, string id, string name, YearMonthDayCalculator yearMonthDayCalculator, Era singleEra) : this(ordinal, id, name, yearMonthDayCalculator, 4, new SingleEraCalculator(singleEra, yearMonthDayCalculator)) { }
/// <summary> /// Returns the days at the start of the given week-year. The week-year may be /// 1 higher or lower than the max/min calendar year. For non-regular rules (i.e. where some weeks /// can be short) it returns the day when the week-year *would* have started if it were regular. /// So this *always* returns a date on firstDayOfWeek. /// </summary> private int GetWeekYearDaysSinceEpoch(YearMonthDayCalculator yearMonthDayCalculator, [Trusted] int weekYear) { unchecked { // Need to be slightly careful here, as the week-year can reasonably be (just) outside the calendar year range. // However, YearMonthDayCalculator.GetStartOfYearInDays already handles min/max -/+ 1. int startOfCalendarYear = yearMonthDayCalculator.GetStartOfYearInDays(weekYear); int startOfYearDayOfWeek = unchecked(startOfCalendarYear >= -3 ? 1 + ((startOfCalendarYear + 3) % 7) : 7 + ((startOfCalendarYear + 4) % 7)); // How many days have there been from the start of the week containing // the first day of the year, until the first day of the year? To put it another // way, how many days in the week *containing* the start of the calendar year were // in the previous calendar year. // (For example, if the start of the calendar year is Friday and the first day of the week is Monday, // this will be 4.) int daysIntoWeek = ((startOfYearDayOfWeek - (int)firstDayOfWeek) + 7) % 7; int startOfWeekContainingStartOfCalendarYear = startOfCalendarYear - daysIntoWeek; bool startOfYearIsInWeek1 = (7 - daysIntoWeek >= minDaysInFirstWeek); return startOfYearIsInWeek1 ? startOfWeekContainingStartOfCalendarYear : startOfWeekContainingStartOfCalendarYear + 7; } }
internal WeekYearCalculator(YearMonthDayCalculator yearMonthDayCalculator, int minDaysInFirstWeek) { this.yearMonthDayCalculator = yearMonthDayCalculator; this.minDaysInFirstWeek = minDaysInFirstWeek; }
private CalendarSystem(string name, YearMonthDayCalculator yearMonthDayCalculator, int minDaysInFirstWeek) : this(CreateIdFromNameAndMinDaysInFirstWeek(name, minDaysInFirstWeek), name, yearMonthDayCalculator, minDaysInFirstWeek) { }
private CalendarSystem(CalendarOrdinal ordinal, string id, string name, YearMonthDayCalculator yearMonthDayCalculator, Era singleEra) : this(ordinal, id, name, yearMonthDayCalculator, new SingleEraCalculator(singleEra, yearMonthDayCalculator)) { }
internal MonthsPeriodField(YearMonthDayCalculator calculator) { this.calculator = calculator; }