CheckAddResult() 정적인 개인적인 메소드

static private CheckAddResult ( long ticks, DateTime minValue, DateTime maxValue ) : void
ticks long
minValue DateTime
maxValue DateTime
리턴 void
예제 #1
0
        public override DateTime AddYears(DateTime time, int years)
        {
            int datePart = this.GetDatePart(time.Ticks, 0);
            int month    = this.GetDatePart(time.Ticks, 2);
            int day      = this.GetDatePart(time.Ticks, 3);

            datePart += years;
            this.CheckHebrewYearValue(datePart, 0, "years");
            int monthsInYear = this.GetMonthsInYear(datePart, 0);

            if (month > monthsInYear)
            {
                month = monthsInYear;
            }
            int daysInMonth = this.GetDaysInMonth(datePart, month);

            if (day > daysInMonth)
            {
                day = daysInMonth;
            }
            long ticks = this.ToDateTime(datePart, month, day, 0, 0, 0, 0).Ticks + (time.Ticks % 0xc92a69c000L);

            Calendar.CheckAddResult(ticks, this.MinSupportedDateTime, this.MaxSupportedDateTime);
            return(new DateTime(ticks));
        }
예제 #2
0
        public override DateTime AddMonths(DateTime time, int months)
        {
            if ((months < -120000) || (months > 0x1d4c0))
            {
                throw new ArgumentOutOfRangeException("months", string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), new object[] { -120000, 0x1d4c0 }));
            }
            int datePart = this.GetDatePart(time.Ticks, 0);
            int month    = this.GetDatePart(time.Ticks, 2);
            int d        = this.GetDatePart(time.Ticks, 3);
            int num4     = (month - 1) + months;

            if (num4 >= 0)
            {
                month     = (num4 % 12) + 1;
                datePart += num4 / 12;
            }
            else
            {
                month     = 12 + ((num4 + 1) % 12);
                datePart += (num4 - 11) / 12;
            }
            int daysInMonth = this.GetDaysInMonth(datePart, month);

            if (d > daysInMonth)
            {
                d = daysInMonth;
            }
            long ticks = (this.GetAbsoluteDateHijri(datePart, month, d) * 0xc92a69c000L) + (time.Ticks % 0xc92a69c000L);

            Calendar.CheckAddResult(ticks, this.MinSupportedDateTime, this.MaxSupportedDateTime);
            return(new DateTime(ticks));
        }
예제 #3
0
        /// <summary>Calculates the date that is the specified number of years away from the specified date.</summary>
        /// <param name="time">The <see cref="T:System.DateTime" /> to which to add <paramref name="years" />. </param>
        /// <param name="years">The number of years to add. </param>
        /// <returns>A new <see cref="T:System.DateTime" /> that results from adding the specified number of years to the <paramref name="time" /> parameter.</returns>
        /// <exception cref="T:System.ArgumentException">The result is outside the supported range of a <see cref="T:System.DateTime" />. </exception>
        /// <exception cref="T:System.ArgumentOutOfRangeException">
        ///         <paramref name="time" /> is less than <see cref="P:System.Globalization.Calendar.MinSupportedDateTime" /> or greater than <see cref="P:System.Globalization.Calendar.MaxSupportedDateTime" />.</exception>
        // Token: 0x06002F1B RID: 12059 RVA: 0x000B4C40 File Offset: 0x000B2E40
        public override DateTime AddYears(DateTime time, int years)
        {
            this.CheckTicksRange(time.Ticks);
            int num  = 0;
            int num2 = 0;
            int num3 = 0;

            this.TimeToLunar(time, ref num, ref num2, ref num3);
            num += years;
            if (num2 == 13 && !this.InternalIsLeapYear(num))
            {
                num2 = 12;
                num3 = this.InternalGetDaysInMonth(num, num2);
            }
            int num4 = this.InternalGetDaysInMonth(num, num2);

            if (num3 > num4)
            {
                num3 = num4;
            }
            DateTime result = this.LunarToTime(time, num, num2, num3);

            Calendar.CheckAddResult(result.Ticks, this.MinSupportedDateTime, this.MaxSupportedDateTime);
            return(result);
        }
예제 #4
0
        /// <summary>返回与指定 <see cref="T:System.DateTime" /> 相距指定年数的 <see cref="T:System.DateTime" />。</summary>
        /// <returns>将指定年数添加到指定的 <see cref="T:System.DateTime" /> 中时得到的 <see cref="T:System.DateTime" />。</returns>
        /// <param name="time">
        /// <see cref="T:System.DateTime" />,将向其添加 <paramref name="years" />。</param>
        /// <param name="years">要添加的年数。</param>
        /// <exception cref="T:System.ArgumentException">结果 <see cref="T:System.DateTime" /> 超出了支持的范围。</exception>
        public override DateTime AddYears(DateTime time, int years)
        {
            int datePart = this.GetDatePart(time.Ticks, 0);
            int month    = this.GetDatePart(time.Ticks, 2);
            int day      = this.GetDatePart(time.Ticks, 3);
            int num      = datePart + years;

            HebrewCalendar.CheckHebrewYearValue(num, 0, "years");
            int monthsInYear = this.GetMonthsInYear(num, 0);

            if (month > monthsInYear)
            {
                month = monthsInYear;
            }
            int daysInMonth = this.GetDaysInMonth(num, month);

            if (day > daysInMonth)
            {
                day = daysInMonth;
            }
            long     ticks = this.ToDateTime(num, month, day, 0, 0, 0, 0).Ticks + time.Ticks % 864000000000L;
            DateTime supportedDateTime1 = this.MinSupportedDateTime;
            DateTime supportedDateTime2 = this.MaxSupportedDateTime;

            Calendar.CheckAddResult(ticks, supportedDateTime1, supportedDateTime2);
            return(new DateTime(ticks));
        }
예제 #5
0
        /// <summary>Returns a <see cref="T:System.DateTime" /> that is the specified number of months away from the specified <see cref="T:System.DateTime" />.</summary>
        /// <param name="time">The <see cref="T:System.DateTime" /> to which to add months. </param>
        /// <param name="months">The number of months to add. </param>
        /// <returns>The <see cref="T:System.DateTime" /> that results from adding the specified number of months to the specified <see cref="T:System.DateTime" />.</returns>
        /// <exception cref="T:System.ArgumentException">The resulting <see cref="T:System.DateTime" /> is outside the supported range. </exception>
        /// <exception cref="T:System.ArgumentOutOfRangeException">
        ///         <paramref name="months" /> is less than -120000.-or-
        ///         <paramref name="months" /> is greater than 120000. </exception>
        // Token: 0x06002F49 RID: 12105 RVA: 0x000B53F8 File Offset: 0x000B35F8
        public override DateTime AddMonths(DateTime time, int months)
        {
            if (months < -120000 || months > 120000)
            {
                throw new ArgumentOutOfRangeException("months", string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), -120000, 120000));
            }
            int num  = JulianCalendar.GetDatePart(time.Ticks, 0);
            int num2 = JulianCalendar.GetDatePart(time.Ticks, 2);
            int num3 = JulianCalendar.GetDatePart(time.Ticks, 3);
            int num4 = num2 - 1 + months;

            if (num4 >= 0)
            {
                num2 = num4 % 12 + 1;
                num += num4 / 12;
            }
            else
            {
                num2 = 12 + (num4 + 1) % 12;
                num += (num4 - 11) / 12;
            }
            int[] array = (num % 4 == 0 && (num % 100 != 0 || num % 400 == 0)) ? JulianCalendar.DaysToMonth366 : JulianCalendar.DaysToMonth365;
            int   num5  = array[num2] - array[num2 - 1];

            if (num3 > num5)
            {
                num3 = num5;
            }
            long ticks = JulianCalendar.DateToTicks(num, num2, num3) + time.Ticks % 864000000000L;

            Calendar.CheckAddResult(ticks, this.MinSupportedDateTime, this.MaxSupportedDateTime);
            return(new DateTime(ticks));
        }
예제 #6
0
        /// <summary>Returns a <see cref="T:System.DateTime" /> object that is offset the specified number of months from the specified <see cref="T:System.DateTime" /> object.</summary>
        /// <param name="time">The <see cref="T:System.DateTime" /> to which to add months. </param>
        /// <param name="months">The positive or negative number of months to add. </param>
        /// <returns>A <see cref="T:System.DateTime" /> object that represents the date yielded by adding the number of months specified by the <paramref name="months" /> parameter to the date specified by the <paramref name="time" /> parameter.</returns>
        /// <exception cref="T:System.ArgumentException">The resulting <see cref="T:System.DateTime" /> is outside the supported range. </exception>
        /// <exception cref="T:System.ArgumentOutOfRangeException">
        ///         <paramref name="months" /> is less than -120,000 or greater than 120,000. </exception>
        // Token: 0x06002F7D RID: 12157 RVA: 0x000B5C2C File Offset: 0x000B3E2C
        public override DateTime AddMonths(DateTime time, int months)
        {
            if (months < -120000 || months > 120000)
            {
                throw new ArgumentOutOfRangeException("months", string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), -120000, 120000));
            }
            int num  = this.GetDatePart(time.Ticks, 0);
            int num2 = this.GetDatePart(time.Ticks, 2);
            int num3 = this.GetDatePart(time.Ticks, 3);
            int num4 = num2 - 1 + months;

            if (num4 >= 0)
            {
                num2 = num4 % 12 + 1;
                num += num4 / 12;
            }
            else
            {
                num2 = 12 + (num4 + 1) % 12;
                num += (num4 - 11) / 12;
            }
            int daysInMonth = this.GetDaysInMonth(num, num2);

            if (num3 > daysInMonth)
            {
                num3 = daysInMonth;
            }
            long ticks = this.GetAbsoluteDatePersian(num, num2, num3) * 864000000000L + time.Ticks % 864000000000L;

            Calendar.CheckAddResult(ticks, this.MinSupportedDateTime, this.MaxSupportedDateTime);
            return(new DateTime(ticks));
        }
        public override DateTime AddMonths(DateTime time, int months)
        {
            if ((months < -120000) || (months > 0x1d4c0))
            {
                throw new ArgumentOutOfRangeException("months", string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), new object[] { -120000, 0x1d4c0 }));
            }
            int datePart = GetDatePart(time.Ticks, 0);
            int index    = GetDatePart(time.Ticks, 2);
            int day      = GetDatePart(time.Ticks, 3);
            int num4     = (index - 1) + months;

            if (num4 >= 0)
            {
                index     = (num4 % 12) + 1;
                datePart += num4 / 12;
            }
            else
            {
                index     = 12 + ((num4 + 1) % 12);
                datePart += (num4 - 11) / 12;
            }
            int[] numArray = (((datePart % 4) == 0) && (((datePart % 100) != 0) || ((datePart % 400) == 0))) ? DaysToMonth366 : DaysToMonth365;
            int   num5     = numArray[index] - numArray[index - 1];

            if (day > num5)
            {
                day = num5;
            }
            long ticks = DateToTicks(datePart, index, day) + (time.Ticks % 0xc92a69c000L);

            Calendar.CheckAddResult(ticks, this.MinSupportedDateTime, this.MaxSupportedDateTime);
            return(new DateTime(ticks));
        }
        public override DateTime AddYears(DateTime time, int years)
        {
            this.CheckTicksRange(time.Ticks);
            int year  = 0;
            int month = 0;
            int day   = 0;

            this.TimeToLunar(time, ref year, ref month, ref day);
            year += years;
            if ((month == 13) && !this.InternalIsLeapYear(year))
            {
                month = 12;
                day   = this.InternalGetDaysInMonth(year, month);
            }
            int daysInMonth = this.InternalGetDaysInMonth(year, month);

            if (day > daysInMonth)
            {
                day = daysInMonth;
            }
            DateTime time2 = this.LunarToTime(time, year, month, day);

            Calendar.CheckAddResult(time2.Ticks, this.MinSupportedDateTime, this.MaxSupportedDateTime);
            return(time2);
        }
예제 #9
0
        // Returns the DateTime resulting from adding the given number of
        // years to the specified DateTime. The result is computed by incrementing
        // (or decrementing) the year part of the specified DateTime by value
        // years. If the month and day of the specified DateTime is 2/29, and if the
        // resulting year is not a leap year, the month and day of the resulting
        // DateTime becomes 2/28. Otherwise, the month, day, and time-of-day
        // parts of the result are the same as those of the specified DateTime.
        //

        public override DateTime AddYears(DateTime time, int years)
        {
            int y = GetDatePart(time.Ticks, DatePartYear);
            int m = GetDatePart(time.Ticks, DatePartMonth);
            int d = GetDatePart(time.Ticks, DatePartDay);

            y += years;
            CheckHebrewYearValue(y, Calendar.CurrentEra, nameof(years));

            int months = GetMonthsInYear(y, CurrentEra);

            if (m > months)
            {
                m = months;
            }

            int days = GetDaysInMonth(y, m);

            if (d > days)
            {
                d = days;
            }

            long ticks = ToDateTime(y, m, d, 0, 0, 0, 0).Ticks + (time.Ticks % TicksPerDay);

            Calendar.CheckAddResult(ticks, MinSupportedDateTime, MaxSupportedDateTime);
            return(new DateTime(ticks));
        }
예제 #10
0
        /// <summary>Calculates the date that is the specified number of months away from the specified date.</summary>
        /// <param name="time">The <see cref="T:System.DateTime" /> to which to add <paramref name="months" />. </param>
        /// <param name="months">The number of months to add. </param>
        /// <returns>A new <see cref="T:System.DateTime" /> that results from adding the specified number of months to the <paramref name="time" /> parameter.</returns>
        /// <exception cref="T:System.ArgumentException">The result is outside the supported range of a <see cref="T:System.DateTime" />. </exception>
        /// <exception cref="T:System.ArgumentOutOfRangeException">
        ///         <paramref name="months" /> is less than -120000 or greater than 120000. -or-
        ///         <paramref name="time" /> is less than <see cref="P:System.Globalization.Calendar.MinSupportedDateTime" /> or greater than <see cref="P:System.Globalization.Calendar.MaxSupportedDateTime" />.</exception>
        // Token: 0x06002F1A RID: 12058 RVA: 0x000B4B34 File Offset: 0x000B2D34
        public override DateTime AddMonths(DateTime time, int months)
        {
            if (months < -120000 || months > 120000)
            {
                throw new ArgumentOutOfRangeException("months", Environment.GetResourceString("ArgumentOutOfRange_Range", new object[]
                {
                    -120000,
                    120000
                }));
            }
            this.CheckTicksRange(time.Ticks);
            int num  = 0;
            int num2 = 0;
            int num3 = 0;

            this.TimeToLunar(time, ref num, ref num2, ref num3);
            int i = num2 + months;

            if (i > 0)
            {
                int num4 = this.InternalIsLeapYear(num) ? 13 : 12;
                while (i - num4 > 0)
                {
                    i -= num4;
                    num++;
                    num4 = (this.InternalIsLeapYear(num) ? 13 : 12);
                }
                num2 = i;
            }
            else
            {
                while (i <= 0)
                {
                    int num5 = this.InternalIsLeapYear(num - 1) ? 13 : 12;
                    i += num5;
                    num--;
                }
                num2 = i;
            }
            int num6 = this.InternalGetDaysInMonth(num, num2);

            if (num3 > num6)
            {
                num3 = num6;
            }
            DateTime result = this.LunarToTime(time, num, num2, num3);

            Calendar.CheckAddResult(result.Ticks, this.MinSupportedDateTime, this.MaxSupportedDateTime);
            return(result);
        }
예제 #11
0
        internal DateTime Add(DateTime time, double value, int scale)
        {
            double num1 = value * (double)scale + (value >= 0.0 ? 0.5 : -0.5);

            if (num1 <= -315537897600000.0 || num1 >= 315537897600000.0)
            {
                throw new ArgumentOutOfRangeException("value", Environment.GetResourceString("ArgumentOutOfRange_AddValue"));
            }
            long     num2  = (long)num1;
            long     ticks = time.Ticks + num2 * 10000L;
            DateTime supportedDateTime1 = this.MinSupportedDateTime;
            DateTime supportedDateTime2 = this.MaxSupportedDateTime;

            Calendar.CheckAddResult(ticks, supportedDateTime1, supportedDateTime2);
            return(new DateTime(ticks));
        }
        /// <summary>计算与指定日期相距指定月数的日期。</summary>
        /// <returns>一个新的 <see cref="T:System.DateTime" />,通过在 <paramref name="time" /> 参数中添加指定的月数得到。</returns>
        /// <param name="time">
        /// <see cref="T:System.DateTime" />,将向其添加 <paramref name="months" />。</param>
        /// <param name="months">要添加的月数。</param>
        /// <exception cref="T:System.ArgumentException">结果超出了 <see cref="T:System.DateTime" /> 支持的范围。</exception>
        /// <exception cref="T:System.ArgumentOutOfRangeException">
        /// <paramref name="months" /> 小于 -120,000 或大于 120,000。- 或 -<paramref name="time" /> 小于 <see cref="P:System.Globalization.Calendar.MinSupportedDateTime" /> 或大于 <see cref="P:System.Globalization.Calendar.MaxSupportedDateTime" />。</exception>
        public override DateTime AddMonths(DateTime time, int months)
        {
            if (months < -120000 || months > 120000)
            {
                throw new ArgumentOutOfRangeException("months", Environment.GetResourceString("ArgumentOutOfRange_Range", (object)-120000, (object)120000));
            }
            this.CheckTicksRange(time.Ticks);
            int year   = 0;
            int month1 = 0;
            int day    = 0;

            this.TimeToLunar(time, ref year, ref month1, ref day);
            int num1 = month1 + months;
            int month2;

            if (num1 > 0)
            {
                for (int index = this.InternalIsLeapYear(year) ? 13 : 12; num1 - index > 0; index = this.InternalIsLeapYear(year) ? 13 : 12)
                {
                    num1 -= index;
                    ++year;
                }
                month2 = num1;
            }
            else
            {
                while (num1 <= 0)
                {
                    int num2 = this.InternalIsLeapYear(year - 1) ? 13 : 12;
                    num1 += num2;
                    --year;
                }
                month2 = num1;
            }
            int daysInMonth = this.InternalGetDaysInMonth(year, month2);

            if (day > daysInMonth)
            {
                day = daysInMonth;
            }
            DateTime time1 = this.LunarToTime(time, year, month2, day);

            Calendar.CheckAddResult(time1.Ticks, this.MinSupportedDateTime, this.MaxSupportedDateTime);
            return(time1);
        }
        public override DateTime AddMonths(DateTime time, int months)
        {
            if ((months < -120000) || (months > 0x1d4c0))
            {
                throw new ArgumentOutOfRangeException("months", string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), new object[] { -120000, 0x1d4c0 }));
            }
            this.CheckTicksRange(time.Ticks);
            int year  = 0;
            int month = 0;
            int day   = 0;

            this.TimeToLunar(time, ref year, ref month, ref day);
            int num4 = month + months;

            if (num4 <= 0)
            {
                while (num4 <= 0)
                {
                    int num6 = this.InternalIsLeapYear(year - 1) ? 13 : 12;
                    num4 += num6;
                    year--;
                }
                month = num4;
            }
            else
            {
                for (int i = this.InternalIsLeapYear(year) ? 13 : 12; (num4 - i) > 0; i = this.InternalIsLeapYear(year) ? 13 : 12)
                {
                    num4 -= i;
                    year++;
                }
                month = num4;
            }
            int daysInMonth = this.InternalGetDaysInMonth(year, month);

            if (day > daysInMonth)
            {
                day = daysInMonth;
            }
            DateTime time2 = this.LunarToTime(time, year, month, day);

            Calendar.CheckAddResult(time2.Ticks, this.MinSupportedDateTime, this.MaxSupportedDateTime);
            return(time2);
        }
예제 #14
0
        // Returns the DateTime resulting from adding the given number of
        // months to the specified DateTime. The result is computed by incrementing
        // (or decrementing) the year and month parts of the specified DateTime by
        // value months, and, if required, adjusting the day part of the
        // resulting date downwards to the last day of the resulting month in the
        // resulting year. The time-of-day part of the result is the same as the
        // time-of-day part of the specified DateTime.
        //
        // In more precise terms, considering the specified DateTime to be of the
        // form y / m / d + t, where y is the
        // year, m is the month, d is the day, and t is the
        // time-of-day, the result is y1 / m1 / d1 + t,
        // where y1 and m1 are computed by adding value months
        // to y and m, and d1 is the largest value less than
        // or equal to d that denotes a valid day in month m1 of year
        // y1.
        //


        public override DateTime AddMonths(DateTime time, int months)
        {
            if (months < -120000 || months > 120000)
            {
                throw new ArgumentOutOfRangeException(
                            nameof(months),
                            String.Format(
                                CultureInfo.CurrentCulture,
                                SR.ArgumentOutOfRange_Range,
                                -120000,
                                120000));
            }
            Contract.EndContractBlock();
            // Get the date in UmAlQura calendar.
            int y = GetDatePart(time, DatePartYear);
            int m = GetDatePart(time, DatePartMonth);
            int d = GetDatePart(time, DatePartDay);
            int i = m - 1 + months;

            if (i >= 0)
            {
                m = i % 12 + 1;
                y = y + i / 12;
            }
            else
            {
                m = 12 + (i + 1) % 12;
                y = y + (i - 11) / 12;
            }

            if (d > 29)
            {
                int days = GetDaysInMonth(y, m);
                if (d > days)
                {
                    d = days;
                }
            }
            CheckYearRange(y, UmAlQuraEra);
            DateTime dt = new DateTime(GetAbsoluteDateUmAlQura(y, m, d) * TicksPerDay + time.Ticks % TicksPerDay);
            Calendar.CheckAddResult(dt.Ticks, MinSupportedDateTime, MaxSupportedDateTime);
            return (dt);
        }
예제 #15
0
        // Returns the DateTime resulting from adding the given number of
        // months to the specified DateTime. The result is computed by incrementing
        // (or decrementing) the year and month parts of the specified DateTime by
        // value months, and, if required, adjusting the day part of the
        // resulting date downwards to the last day of the resulting month in the
        // resulting year. The time-of-day part of the result is the same as the
        // time-of-day part of the specified DateTime.
        //
        // In more precise terms, considering the specified DateTime to be of the
        // form y / m / d + t, where y is the
        // year, m is the month, d is the day, and t is the
        // time-of-day, the result is y1 / m1 / d1 + t,
        // where y1 and m1 are computed by adding value months
        // to y and m, and d1 is the largest value less than
        // or equal to d that denotes a valid day in month m1 of year
        // y1.
        //

        public override DateTime AddMonths(DateTime time, int months)
        {
            if (months < -120000 || months > 120000)
            {
                throw new ArgumentOutOfRangeException(
                          "months",
                          String.Format(
                              CultureInfo.CurrentCulture,
                              Environment.GetResourceString("ArgumentOutOfRange_Range"),
                              -120000,
                              120000));
            }
            Contract.EndContractBlock();

            int y, m, d;

            time.GetDatePart(out y, out m, out d);

            int i = m - 1 + months;

            if (i >= 0)
            {
                m = i % 12 + 1;
                y = y + i / 12;
            }
            else
            {
                m = 12 + (i + 1) % 12;
                y = y + (i - 11) / 12;
            }
            int[] daysArray = (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0)) ? DaysToMonth366: DaysToMonth365;
            int   days      = (daysArray[m] - daysArray[m - 1]);

            if (d > days)
            {
                d = days;
            }
            long ticks = DateToTicks(y, m, d) + time.Ticks % TicksPerDay;

            Calendar.CheckAddResult(ticks, MinSupportedDateTime, MaxSupportedDateTime);

            return(new DateTime(ticks));
        }
예제 #16
0
        // Returns the DateTime resulting from adding the given number of
        // months to the specified DateTime. The result is computed by incrementing
        // (or decrementing) the year and month parts of the specified DateTime by
        // value months, and, if required, adjusting the day part of the
        // resulting date downwards to the last day of the resulting month in the
        // resulting year. The time-of-day part of the result is the same as the
        // time-of-day part of the specified DateTime.
        //
        // In more precise terms, considering the specified DateTime to be of the
        // form y / m / d + t, where y is the
        // year, m is the month, d is the day, and t is the
        // time-of-day, the result is y1 / m1 / d1 + t,
        // where y1 and m1 are computed by adding value months
        // to y and m, and d1 is the largest value less than
        // or equal to d that denotes a valid day in month m1 of year
        // y1.
        //
        public DateTime AddMonths(DateTime time, int months)
        {
            if (months < -120000 || months > 120000)
            {
                throw new ArgumentOutOfRangeException(
                          "months",
                          String.Format(
                              CultureInfo.CurrentCulture,
                              SR.ArgumentOutOfRange_Range,
                              -120000,
                              120000));
            }
            Contract.EndContractBlock();
            CheckTicksRange(time.Ticks);

            int y = GetDatePart(time.Ticks, DatePartYear);
            int m = GetDatePart(time.Ticks, DatePartMonth);
            int d = GetDatePart(time.Ticks, DatePartDay);
            int i = m - 1 + months;

            if (i >= 0)
            {
                m = i % 12 + 1;
                y = y + i / 12;
            }
            else
            {
                m = 12 + (i + 1) % 12;
                y = y + (i - 11) / 12;
            }
            int[] daysArray = (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0)) ? DaysToMonth366 : DaysToMonth365;
            int   days      = (daysArray[m] - daysArray[m - 1]);

            if (d > days)
            {
                d = days;
            }
            long ticks = DateToTicks(y, m, d) + (time.Ticks % TicksPerDay);

            Calendar.CheckAddResult(ticks, m_Cal.MinSupportedDateTime, m_Cal.MaxSupportedDateTime);
            return(new DateTime(ticks));
        }
예제 #17
0
        // Returns the DateTime resulting from adding the given number of
        // months to the specified DateTime. The result is computed by incrementing
        // (or decrementing) the year and month parts of the specified DateTime by
        // value months, and, if required, adjusting the day part of the
        // resulting date downwards to the last day of the resulting month in the
        // resulting year. The time-of-day part of the result is the same as the
        // time-of-day part of the specified DateTime.
        //
        // In more precise terms, considering the specified DateTime to be of the
        // form y / m / d + t, where y is the
        // year, m is the month, d is the day, and t is the
        // time-of-day, the result is y1 / m1 / d1 + t,
        // where y1 and m1 are computed by adding value months
        // to y and m, and d1 is the largest value less than
        // or equal to d that denotes a valid day in month m1 of year
        // y1.
        //


        public override DateTime AddMonths(DateTime time, int months)
        {
            if (months < -120000 || months > 120000)
            {
                throw new ArgumentOutOfRangeException(
                          nameof(months),
                          String.Format(
                              CultureInfo.CurrentCulture,
                              Environment.GetResourceString("ArgumentOutOfRange_Range"),
                              -120000,
                              120000));
            }
            Contract.EndContractBlock();
            // Get the date in Persian calendar.
            int y = GetDatePart(time.Ticks, DatePartYear);
            int m = GetDatePart(time.Ticks, DatePartMonth);
            int d = GetDatePart(time.Ticks, DatePartDay);
            int i = m - 1 + months;

            if (i >= 0)
            {
                m = i % 12 + 1;
                y = y + i / 12;
            }
            else
            {
                m = 12 + (i + 1) % 12;
                y = y + (i - 11) / 12;
            }
            int days = GetDaysInMonth(y, m);

            if (d > days)
            {
                d = days;
            }
            long ticks = GetAbsoluteDatePersian(y, m, d) * TicksPerDay + time.Ticks % TicksPerDay;

            Calendar.CheckAddResult(ticks, MinSupportedDateTime, MaxSupportedDateTime);
            return(new DateTime(ticks));
        }
        public DateTime AddMonths(DateTime time, int months)
        {
            if (months < -120000 || months > 120000)
            {
                throw new ArgumentOutOfRangeException("months", string.Format((IFormatProvider)CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), (object)-120000, (object)120000));
            }
            this.CheckTicksRange(time.Ticks);
            int datePart1 = this.GetDatePart(time.Ticks, 0);
            int datePart2 = this.GetDatePart(time.Ticks, 2);
            int day       = this.GetDatePart(time.Ticks, 3);
            int num1      = datePart2 - 1 + months;
            int month;
            int year;

            if (num1 >= 0)
            {
                month = num1 % 12 + 1;
                year  = datePart1 + num1 / 12;
            }
            else
            {
                month = 12 + (num1 + 1) % 12;
                year  = datePart1 + (num1 - 11) / 12;
            }
            int[] numArray = year % 4 != 0 || year % 100 == 0 && year % 400 != 0 ? GregorianCalendarHelper.DaysToMonth365 : GregorianCalendarHelper.DaysToMonth366;
            int   num2     = numArray[month] - numArray[month - 1];

            if (day > num2)
            {
                day = num2;
            }
            long     ticks = GregorianCalendarHelper.DateToTicks(year, month, day) + time.Ticks % 864000000000L;
            DateTime supportedDateTime1 = this.m_Cal.MinSupportedDateTime;
            DateTime supportedDateTime2 = this.m_Cal.MaxSupportedDateTime;

            Calendar.CheckAddResult(ticks, supportedDateTime1, supportedDateTime2);
            return(new DateTime(ticks));
        }
예제 #19
0
        public override DateTime AddMonths(DateTime time, int months)
        {
            if (months < -120000 || months > 120000)
            {
                throw new ArgumentOutOfRangeException(
                          nameof(months),
                          months,
                          SR.Format(SR.ArgumentOutOfRange_Range, -120000, 120000));
            }

            // Get the date in Persian calendar.
            int y = GetDatePart(time.Ticks, DatePartYear);
            int m = GetDatePart(time.Ticks, DatePartMonth);
            int d = GetDatePart(time.Ticks, DatePartDay);
            int i = m - 1 + months;

            if (i >= 0)
            {
                m  = i % 12 + 1;
                y += i / 12;
            }
            else
            {
                m  = 12 + (i + 1) % 12;
                y += (i - 11) / 12;
            }
            int days = GetDaysInMonth(y, m);

            if (d > days)
            {
                d = days;
            }

            long ticks = GetAbsoluteDatePersian(y, m, d) * TicksPerDay + time.Ticks % TicksPerDay;

            Calendar.CheckAddResult(ticks, MinSupportedDateTime, MaxSupportedDateTime);
            return(new DateTime(ticks));
        }
예제 #20
0
        /// <summary>返回与指定 <see cref="T:System.DateTime" /> 相距指定月数的 <see cref="T:System.DateTime" />。</summary>
        /// <returns>将指定的月数添加到指定的 <see cref="T:System.DateTime" /> 中时得到的 <see cref="T:System.DateTime" />。</returns>
        /// <param name="time">将向其添加月数的 <see cref="T:System.DateTime" />。</param>
        /// <param name="months">要添加的月数。</param>
        /// <exception cref="T:System.ArgumentException">产生的 <see cref="T:System.DateTime" />。</exception>
        /// <exception cref="T:System.ArgumentOutOfRangeException">
        /// <paramref name="months" /> 小于 -120000。- 或 -<paramref name="months" /> 大于 120000。</exception>
        /// <PermissionSet>
        ///   <IPermission class="System.Security.Permissions.RegistryPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Read="\" />
        /// </PermissionSet>
        public override DateTime AddMonths(DateTime time, int months)
        {
            if (months < -120000 || months > 120000)
            {
                throw new ArgumentOutOfRangeException("months", string.Format((IFormatProvider)CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), (object)-120000, (object)120000));
            }
            int datePart1 = this.GetDatePart(time.Ticks, 0);
            int datePart2 = this.GetDatePart(time.Ticks, 2);
            int d         = this.GetDatePart(time.Ticks, 3);
            int num1      = datePart2 - 1 + months;
            int num2;
            int num3;

            if (num1 >= 0)
            {
                num2 = num1 % 12 + 1;
                num3 = datePart1 + num1 / 12;
            }
            else
            {
                num2 = 12 + (num1 + 1) % 12;
                num3 = datePart1 + (num1 - 11) / 12;
            }
            int daysInMonth = this.GetDaysInMonth(num3, num2);

            if (d > daysInMonth)
            {
                d = daysInMonth;
            }
            long     ticks = this.GetAbsoluteDateHijri(num3, num2, d) * 864000000000L + time.Ticks % 864000000000L;
            DateTime supportedDateTime1 = this.MinSupportedDateTime;
            DateTime supportedDateTime2 = this.MaxSupportedDateTime;

            Calendar.CheckAddResult(ticks, supportedDateTime1, supportedDateTime2);
            return(new DateTime(ticks));
        }