Example #1
0
        /// <summary>
        /// Adds the specified number of days to the value of this instance.
        /// </summary>
        /// <param name="numberOfDays">A number of whole days.
        /// The value parameter can be negative or positive.</param>
        public CivilDate AddDays(long numberOfDays)
        {
            RataDie currentValue = null;

            currentValue       = ToRataDie();
            currentValue.Days += numberOfDays;
            return(CivilDate.FromRataDie(currentValue));
        }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CivilDate"/> class to the specified year, month, and day.
        /// </summary>
        /// <param name="day">The date as an integer between 1 and 31.</param>
        /// <param name="month">The month as a <see cref="CivilMonth"/> enum between January and December.</param>
        /// <param name="fullYear">The full year, for example, 1976 (and not 76).</param>
        public CivilDate(int fullYear, CivilMonth month, int day)
        {
            int maxDay = 0;

            maxDay    = CivilDate.GetDaysInMonth(fullYear, month);
            _day      = (day > maxDay ? maxDay : day);
            _month    = month;
            _fullYear = fullYear;
        }
Example #3
0
        /// <summary>
        /// Returns a <see cref="CivilDate"/> object set to a date based on its <see cref="RataDie"/> counterpart.
        /// <remarks>See the footnote on page 384 of "Calendrical Calculations, Part II: Three Historical Calendars"
        /// by E. M. Reingold,  N. Dershowitz, and S. M. Clamen, Software--Practice and Experience, Volume 23,
        /// Number 4 (April, 1993), pages 383-404 for an explanation.</remarks>
        /// </summary>
        /// <param name="fixedDate">An <see cref="RataDie"/> object that represents the desired date.</param>
        public static CivilDate FromRataDie(RataDie fixedDate)
        {
            int       day    = 0;
            int       year   = 0;
            int       month  = 0;
            int       mlen   = 0;
            long      d0     = 0L;
            long      n400   = 0L;
            long      d1     = 0L;
            long      n100   = 0L;
            long      d2     = 0L;
            long      n4     = 0L;
            long      d3     = 0L;
            long      n1     = 0L;
            CivilDate result = null;

            d0   = fixedDate.Days - 1L;
            n400 = (int)(d0 / 146097L);
            d1   = (int)(d0 % 146097L);
            n100 = (int)(d1 / 36524L);
            d2   = (int)(d1 % 36524L);
            n4   = (int)(d2 / 1461L);
            d3   = (int)(d2 % 1461L);
            n1   = (int)(d3 / 365L);

            day  = (int)((d3 % 365L) + 1L);
            year = (int)(400L * n400 + 100L * n100 + 4L * n4 + n1);

            if (n100 == 4L || n1 == 4L)
            {
                result = new CivilDate(year, CivilMonth.December, 31);
            }
            else
            {
                year++;
                month = 1;                 // Start from January
                while ((mlen = GetDaysInMonth(year, (CivilMonth)month)) < day)
                {
                    day -= mlen;
                    month++;
                }
                result = new CivilDate(year, (CivilMonth)month, day);
            }

            return(result);
        }