System.Globalization.PersianCalendar.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));
            }
            // 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));
        }

Usage Example

Esempio n. 1
0
 /// <summary>
 /// <para>Returnes a PersianDate object that is offset the specified number of months away from the specified PersianDate</para>
 /// </summary>
 public PersianDate AddMonths(int months)
 {
     return(new PersianDate(persianCalendar.AddMonths(FormalDateTime, months)));
 }