private CalendarSystem(CalendarOrdinal ordinal, string id, string name, YearMonthDayCalculator yearMonthDayCalculator, EraCalculator eraCalculator) { this.Ordinal = ordinal; this.Id = id; this.Name = name; this.YearMonthDayCalculator = yearMonthDayCalculator; 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; }
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; }
public void GetStartOfYearInDays_InOptimizedRange() { IsoCalculator.GetStartOfYearInDays(2000); }
/// <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; } }