AddMonths() public method

public AddMonths ( System.DateTime time, int months ) : System.DateTime
time System.DateTime
months int
return System.DateTime
 public void PosTest3()
 {
     DateTime initialTime;
     int months;
     DateTime resultingTime;
     System.Globalization.Calendar myCalendar = new GregorianCalendar(GregorianCalendarTypes.USEnglish);
     months = -1 * _generator.GetInt32(-55) % c_MAX_MONTHS_NUMBER - 1;
     initialTime = myCalendar.MaxSupportedDateTime;
     resultingTime = myCalendar.AddMonths(initialTime, months);
     VerifyAddMonthsResult(myCalendar, initialTime, resultingTime, months);
 }
 /// <summary>
 /// Inherited code: Requires comment.
 /// </summary>
 /// <param name="time">Inherited code: Requires comment 1.</param>
 /// <param name="months">Inherited code: Requires comment 2.</param>
 /// <returns>Inherited code: Requires comment 3.</returns>
 public static DateTime? AddMonths(DateTime time, int months)
 {
     System.Globalization.Calendar cal = new GregorianCalendar();
     try
     {
         return cal.AddMonths(time, months);
     }
     catch (ArgumentException)
     {
         return null;
     }
 }
        public void PosTest1()
        {
            DateTime initialTime;
            int months;
            DateTime resultingTime;
            System.Globalization.Calendar myCalendar = new GregorianCalendar(GregorianCalendarTypes.USEnglish);
            months = 0;
            initialTime = DateTime.Now;

            resultingTime = myCalendar.AddMonths(initialTime, months);
            Assert.Equal(initialTime, resultingTime);
        }
 public void PosTest4()
 {
     DateTime initialTime;
     int months;
     DateTime resultingTime;
     System.Globalization.Calendar myCalendar = new GregorianCalendar(GregorianCalendarTypes.USEnglish);
     months = -1;
     long maxTimeInTicks = myCalendar.MaxSupportedDateTime.Ticks;
     long minTimeInTikcs = myCalendar.MinSupportedDateTime.Ticks;
     initialTime = new DateTime(_generator.GetInt64(-55) % (maxTimeInTicks + 1));
     resultingTime = myCalendar.AddMonths(initialTime, months);
     VerifyAddMonthsResult(myCalendar, initialTime, resultingTime, months);
 }
 public void PosTest6()
 {
     DateTime initialTime;
     int months;
     DateTime resultingTime;
     System.Globalization.Calendar myCalendar = new GregorianCalendar(GregorianCalendarTypes.USEnglish);
     months = 48;
     initialTime = myCalendar.ToDateTime(1996, 2, 29, 10, 30, 24, 0);
     resultingTime = myCalendar.AddMonths(initialTime, months);
     VerifyAddMonthsResult(myCalendar, initialTime, resultingTime, months);
 }
 public void NegTest3()
 {
     DateTime time;
     int months;
     System.Globalization.Calendar myCalendar;
     myCalendar = new GregorianCalendar(GregorianCalendarTypes.USEnglish);
     time = myCalendar.MaxSupportedDateTime;
     months = 1;
     Assert.Throws<ArgumentOutOfRangeException>(() =>
    {
        myCalendar.AddMonths(time, months);
    });
 }
 public void NegTest2()
 {
     DateTime time;
     int months;
     System.Globalization.Calendar myCalendar;
     time = DateTime.Now;
     months = c_MAX_MONTHS_NUMBER + 1 + _generator.GetInt32(-55) % (int.MaxValue - c_MAX_MONTHS_NUMBER);
     myCalendar = new GregorianCalendar(GregorianCalendarTypes.USEnglish);
     Assert.Throws<ArgumentOutOfRangeException>(() =>
    {
        myCalendar.AddMonths(time, months);
    });
 }
Example #8
0
	[Test] // bug #81783
	public void GregorianAddMonth ()
	{
		GregorianCalendar c = new GregorianCalendar ();
		DateTime d = new DateTime (2007, 5, 31);
		DateTime prev = c.AddMonths (d, -1);
		Assert.AreEqual (4, prev.Month, "prev");
		DateTime next = c.AddMonths (d, 1);
		Assert.AreEqual (6, next.Month, "next");

		d = new DateTime (2003, 12, 5);
		prev = c.AddMonths (d, -13);
		Assert.AreEqual (new DateTime (2002, 11, 5), prev, "prev2");
		next = c.AddMonths (d, 6);
		Assert.AreEqual (new DateTime (2004, 6, 5), next, "next2");
	}
Example #9
0
        public void TestBug56688_4()
        {
            XSSFWorkbook excel = XSSFTestDataSamples.OpenSampleWorkbook("56688_4.xlsx");

            Calendar calendar = new GregorianCalendar(GregorianCalendarTypes.USEnglish);
            DateTime time = calendar.AddMonths(DateTime.Now, 2);
            double excelDate = DateUtil.GetExcelDate(time);
            NumberEval eval = new NumberEval(Math.Floor(excelDate));
            //CheckValue(excel, eval.StringValue + ".0");
            CheckValue(excel, eval.StringValue);
        }
Example #10
0
 private void ProcessUpKey() 
 {
     System.Globalization.Calendar _cal = new GregorianCalendar();
     if (this.DisplayMode == CalendarMode.Month) 
     {
         DateTime selectedDate = _cal.AddDays(this.SelectedDate.GetValueOrDefault(DateTime.Today), -7);
         if (IsValidDate(this, selectedDate)) 
         { 
             OnDayClick(selectedDate);
         } 
     }
     else
     { 
         Debug.Assert(this.DisplayMode == CalendarMode.Year);
         DateTime selectedMonth = _cal.AddMonths(this._selectedMonth, -4);
         OnSelectedMonthChanged(selectedMonth); 
     } 
 }
Example #11
0
 private void ProcessEndKey() 
 { 
     System.Globalization.Calendar _cal = new GregorianCalendar();
     if (this.DisplayMode == CalendarMode.Month) 
     {
         if (this.DisplayDate != null)
         { 
             DateTime selectedDate = new DateTime(((DateTime)this.DisplayDate).Year, ((DateTime)this.DisplayDate).Month, 1);
             selectedDate = _cal.AddMonths(selectedDate, 1);
             selectedDate = _cal.AddDays(selectedDate, -1); 
             if (IsValidDate(this, selectedDate)) 
             {
                 OnDayClick(selectedDate); 
             }
         }
     } 
     else
     {
         Debug.Assert(this.DisplayMode == CalendarMode.Year); 
         DateTime selectedMonth = new DateTime(this._selectedMonth.Year, 12, 1); 
         OnSelectedMonthChanged(selectedMonth);
     } 
 }