internal static CalendarDate ToCalendarDate(OrdinalDate ordinalDate, CalendarDatePrecision precision) { if (precision == CalendarDatePrecision.Century) { return new CalendarDate(ISO8601Calculator.CenturyOfYear(ordinalDate.Year)); } if (precision == CalendarDatePrecision.Year) { return new CalendarDate(ordinalDate.Year); } var days = ISO8601Calculator.IsLeapYear(ordinalDate.Year) ? DaysToMonth366 : DaysToMonth365; var month = 0; var day = 0; for (int i = days.Length - 1; i >= 0; i--) { if (ordinalDate.Day > days[i]) { month = i + 1; day = ordinalDate.Day - days[i]; break; } } if (precision == CalendarDatePrecision.Month) { return new CalendarDate(ordinalDate.Year, month); } return new CalendarDate(ordinalDate.Year, month, day); }
internal static CalendarDate ToCalendarDate(WeekDate weekDate, CalendarDatePrecision precision) { if (weekDate.Precision != WeekDatePrecision.Day) { throw new ConversionException("The week date must be defined to the day to be converted to a calendar date without information loss."); } return ToOrdinalDate(weekDate).ToCalendarDate(precision); }
public CalendarDate(long year, int month) : this(year) { if (month < 1 || month > 12) { throw new ArgumentOutOfRangeException("month", "The month must be a value from 1 to 12."); } _month = month; _precision = CalendarDatePrecision.Month; }
public CalendarDate(long year, int month, int day) : this(year, month) { if (day < 1 || day > ISO8601Calculator.DaysInMonth(year, month)) { throw new ArgumentOutOfRangeException("day", $"The day must be a value from 1 to {ISO8601Calculator.DaysInMonth(year, month)}."); } _day = day; _precision = CalendarDatePrecision.Day; }
public CalendarDate(long year) { _year = year; _century = ISO8601Calculator.CenturyOfYear(year); _precision = CalendarDatePrecision.Year; }
public CalendarDate ToCalendarDate(CalendarDatePrecision precision) { return WeekDateConverter.ToCalendarDate(this, precision); }