System.Globalization.HebrewCalendar.AddMonths C# (CSharp) Method

AddMonths() public method

public AddMonths ( System.DateTime time, int months ) : System.DateTime
time System.DateTime
months int
return System.DateTime
        public override DateTime AddMonths(DateTime time, int months) {
            try {
                int y = GetDatePart(time.Ticks, DatePartYear);
                int m = GetDatePart(time.Ticks, DatePartMonth);
                int d = GetDatePart(time.Ticks, DatePartDay);


                int monthsInYear;
                int i;
                if (months >= 0) {
                    i = m + months;
                    while (i > (monthsInYear = GetMonthsInYear(y, CurrentEra))) {
                        y++;
                        i -= monthsInYear;
                    }
                } else {
                    if ((i = m + months) <= 0) {
                        months = -months;
                        months -= m;
                        y--;

                        while (months > (monthsInYear = GetMonthsInYear(y, CurrentEra))) {
                            y--;
                            months -= monthsInYear;
                        }
                        monthsInYear = GetMonthsInYear(y, CurrentEra);
                        i = monthsInYear - months;
                    }
                }

                int days = GetDaysInMonth(y, i);
                if (d > days) {
                    d = days;
                }
                return (new DateTime(ToDateTime(y, i, d, 0, 0, 0, 0).Ticks + (time.Ticks % TicksPerDay)));
            }
            // We expect ArgumentException and ArgumentOutOfRangeException (which is subclass of ArgumentException)
            // If exception is thrown in the calls above, we are out of the supported range of this calendar.
            catch (ArgumentException)
            {
                throw new ArgumentOutOfRangeException(
                            "months",
                            String.Format(
                                CultureInfo.CurrentCulture,
                                Environment.GetResourceString("ArgumentOutOfRange_AddValue")));
            }
        }