Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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;
        }
Ejemplo n.º 4
0
        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;
        }
Ejemplo n.º 5
0
 public CalendarDate(long year)
 {
     _year = year;
     _century = ISO8601Calculator.CenturyOfYear(year);
     _precision = CalendarDatePrecision.Year;
 }
Ejemplo n.º 6
0
 public CalendarDate ToCalendarDate(CalendarDatePrecision precision)
 {
     return WeekDateConverter.ToCalendarDate(this, precision);
 }