System.Globalization.EastAsianLunisolarCalendar.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) {
            if (months < -120000 || months > 120000) {
                throw new ArgumentOutOfRangeException(
                            "months",
                            String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), -120000, 120000));
            }

            CheckTicksRange(time.Ticks);

            int y=0;  int m=0; int d=0;
            TimeToLunar(time, ref y, ref m, ref d);

            int i = m + months;
            if (i > 0) {
                int monthsInYear = InternalIsLeapYear(y)?13:12;

                while (i-monthsInYear > 0) {
                    i -= monthsInYear;
                    y++;
                    monthsInYear = InternalIsLeapYear(y)?13:12;
                }
                m = i;
            } else {
                int monthsInYear;
                while (i <= 0) {
                    monthsInYear = InternalIsLeapYear(y-1)?13:12;
                    i += monthsInYear;
                    y--;
                }
                m = i;
            }

            int days = InternalGetDaysInMonth(y, m);
            if (d > days) {
                d = days;
            }
            DateTime dt = LunarToTime(time, y, m, d);

            CheckAddResult(dt.Ticks, MinSupportedDateTime, MaxSupportedDateTime);
            return (dt);
        }