public static void Main() { // Sets a DateTime to April 3, 2002 of the Gregorian calendar. DateTime myDT = new DateTime(2002, 4, 3, new GregorianCalendar()); // Creates an instance of the TaiwanCalendar. TaiwanCalendar myCal = new TaiwanCalendar(); // Displays the values of the DateTime. Console.WriteLine("April 3, 2002 of the Gregorian calendar equals the following in the Taiwan calendar:"); DisplayValues(myCal, myDT); // Adds two years and ten months. myDT = myCal.AddYears(myDT, 2); myDT = myCal.AddMonths(myDT, 10); // Displays the values of the DateTime. Console.WriteLine("After adding two years and ten months:"); DisplayValues(myCal, myDT); }
private void VerificationHelper(DateTime value, int addValue) { System.Globalization.Calendar tc = new TaiwanCalendar(); DateTime newDate = tc.AddYears(value, addValue); _errorNo++; Assert.Equal(newDate.Year, (value.Year + addValue)); if (value.Month == 2) { if ((DateTime.IsLeapYear(value.Year) && value.Day == 29) || (!DateTime.IsLeapYear(value.Year) && value.Day == 28)) { if (DateTime.IsLeapYear(newDate.Year)) { Assert.Equal(29, newDate.Day); } else { Assert.Equal(28, newDate.Day); } } } }