AddYears() public method

public AddYears ( System.DateTime time, int years ) : System.DateTime
time System.DateTime
years int
return System.DateTime
コード例 #1
0
 public void PosTest5()
 {
     DateTime initialTime;
     int years;
     DateTime resultingTime;
     System.Globalization.Calendar myCalendar = new GregorianCalendar(GregorianCalendarTypes.USEnglish);
     years = 13;
     initialTime = myCalendar.ToDateTime(2000, 2, 29, 10, 30, 24, 0);
     resultingTime = myCalendar.AddYears(initialTime, years);
     VerifyAddyearsResult(myCalendar, initialTime, resultingTime, years);
 }
コード例 #2
0
 public void PosTest3()
 {
     DateTime initialTime;
     int years;
     DateTime resultingTime;
     System.Globalization.Calendar myCalendar = new GregorianCalendar(GregorianCalendarTypes.USEnglish);
     years = -99;
     initialTime = myCalendar.MaxSupportedDateTime;
     resultingTime = myCalendar.AddYears(initialTime, years);
     VerifyAddyearsResult(myCalendar, initialTime, resultingTime, years);
 }
コード例 #3
0
 public void PosTest1()
 {
     DateTime initialTime;
     int years;
     DateTime resultingTime;
     System.Globalization.Calendar myCalendar = new GregorianCalendar(GregorianCalendarTypes.USEnglish);
     years = 0;
     initialTime = DateTime.Now;
     resultingTime = myCalendar.AddYears(initialTime, years);
     Assert.Equal(initialTime, resultingTime);
 }
コード例 #4
0
 /// <summary>
 /// Inherited code: Requires comment.
 /// </summary>
 /// <param name="time">Inherited code: Requires comment 1.</param>
 /// <param name="years">Inherited code: Requires comment 2.</param>
 /// <returns>Inherited code: Requires comment 3.</returns>
 public static DateTime? AddYears(DateTime time, int years)
 {
     System.Globalization.Calendar cal = new GregorianCalendar();
     try
     {
         return cal.AddYears(time, years);
     }
     catch (ArgumentException)
     {
         return null;
     }
 }
コード例 #5
0
 public void PosTest4()
 {
     DateTime initialTime;
     int years;
     DateTime resultingTime;
     System.Globalization.Calendar myCalendar = new GregorianCalendar(GregorianCalendarTypes.USEnglish);
     years = 1;
     long maxTimeInTicks = myCalendar.MaxSupportedDateTime.Ticks;
     long minTimeInTikcs = myCalendar.MinSupportedDateTime.Ticks;
     initialTime = new DateTime(_generator.GetInt64(-55) % maxTimeInTicks);
     resultingTime = myCalendar.AddYears(initialTime, years);
     VerifyAddyearsResult(myCalendar, initialTime, resultingTime, years);
 }
コード例 #6
0
ファイル: CalendarTest.cs プロジェクト: GirlD/mono
	public void AddYearOnLeapYear ()
	{
		GregorianCalendar c = new GregorianCalendar ();
		DateTime d = new DateTime (2004, 2, 29);
		DateTime prev = c.AddYears (d, -1);
		Assert.AreEqual (2, prev.Month, "prev");
		DateTime next = c.AddYears (d, 1);
		Assert.AreEqual (2, next.Month, "next");
	}
コード例 #7
0
 public void NegTest1()
 {
     DateTime time;
     int years;
     System.Globalization.Calendar myCalendar;
     time = DateTime.Now;
     years = 9999;
     myCalendar = new GregorianCalendar(GregorianCalendarTypes.USEnglish);
     Assert.Throws<ArgumentOutOfRangeException>(() =>
    {
        myCalendar.AddYears(time, years);
    });
 }
コード例 #8
0
ファイル: Calendar.cs プロジェクト: dfr0/moon
 private void ProcessPageUpKey() 
 {
     System.Globalization.Calendar _cal = new GregorianCalendar(); 
     if (this.DisplayMode == CalendarMode.Month)
     {
         DateTime selectedDate = _cal.AddMonths(this.SelectedDate.GetValueOrDefault(DateTime.Today), -1); 
         if (IsValidDate(this,selectedDate))
         {
             OnDayClick(selectedDate); 
         } 
     }
     else 
     {
         Debug.Assert(this.DisplayMode == CalendarMode.Year);
         DateTime selectedMonth = _cal.AddYears(this._selectedMonth, -1); 
         OnSelectedMonthChanged(selectedMonth);
     }
 }