public static void Main() { // Creates and initializes a TaiwanCalendar. TaiwanCalendar myCal = new TaiwanCalendar(); // Displays the header. Console.Write("YEAR\t"); for (int y = 90; y <= 94; y++) { Console.Write("\t{0}", y); } Console.WriteLine(); // Displays the value of the CurrentEra property. Console.Write("CurrentEra:"); for (int y = 90; y <= 94; y++) { Console.Write("\t{0}", myCal.GetDaysInMonth(y, 2, TaiwanCalendar.CurrentEra)); } Console.WriteLine(); // Displays the values in the Eras property. for (int i = 0; i < myCal.Eras.Length; i++) { Console.Write("Era {0}:\t", myCal.Eras[i]); for (int y = 90; y <= 94; y++) { Console.Write("\t{0}", myCal.GetDaysInMonth(y, 2, myCal.Eras[i])); } Console.WriteLine(); } }
public static void Main() { // Creates and initializes a TaiwanCalendar. TaiwanCalendar myCal = new TaiwanCalendar(); // Creates a holder for the last day of the second month (February). int iLastDay; // Displays the header. Console.Write( "YEAR\t" ); for ( int y = 90; y <= 94; y++ ) Console.Write( "\t{0}", y ); Console.WriteLine(); // Checks five years in the current era. Console.Write( "CurrentEra:" ); for ( int y = 90; y <= 94; y++ ) { iLastDay = myCal.GetDaysInMonth( y, 2, TaiwanCalendar.CurrentEra ); Console.Write( "\t{0}", myCal.IsLeapDay( y, 2, iLastDay, TaiwanCalendar.CurrentEra ) ); } Console.WriteLine(); // Checks five years in each of the eras. for ( int i = 0; i < myCal.Eras.Length; i++ ) { Console.Write( "Era {0}:\t", myCal.Eras[i] ); for ( int y = 90; y <= 94; y++ ) { iLastDay = myCal.GetDaysInMonth( y, 2, myCal.Eras[i] ); Console.Write( "\t{0}", myCal.IsLeapDay( y, 2, iLastDay, myCal.Eras[i] ) ); } Console.WriteLine(); } }
public void NegTest3() { System.Globalization.Calendar tc = new TaiwanCalendar(); Random rand = new Random(-55); int year = rand.Next(tc.MinSupportedDateTime.Year, tc.MaxSupportedDateTime.Year - 1911); int month = rand.Next(1, 13); int day = rand.Next(Int32.MinValue, 1); int hour = rand.Next(0, 24); int minute = rand.Next(0, 60); int second = rand.Next(0, 60); int milliSecond = rand.Next(0, 1000); int era; era = tc.Eras[0]; Assert.Throws <ArgumentOutOfRangeException>(() => { tc.ToDateTime(year, month, day, hour, minute, second, milliSecond, era); }); day = rand.Next(tc.GetDaysInMonth(year, month, era) + 1, Int32.MaxValue); Assert.Throws <ArgumentOutOfRangeException>(() => { tc.ToDateTime(year, month, day, hour, minute, second, milliSecond, era); }); }
public static void GetDaysInMonth(int year, int month) { TaiwanCalendar calendar = new TaiwanCalendar(); int expected; if (calendar.IsLeapYear(year)) { expected = s_daysPerMonthLeapYear[month]; } else { expected = s_daysPerMonthCommonYear[month]; } Assert.Equal(expected, calendar.GetDaysInMonth(year, month)); Assert.Equal(expected, calendar.GetDaysInMonth(year, month, 0)); Assert.Equal(expected, calendar.GetDaysInMonth(year, month, 1)); }
public void PosTest1() { System.Globalization.Calendar tc = new TaiwanCalendar(); Random rand = new Random(-55); int year = rand.Next(tc.MinSupportedDateTime.Year, tc.MaxSupportedDateTime.Year - 1911); int month = rand.Next(1, 12); int day = rand.Next(1, tc.GetDaysInMonth(year, month) + 1); DateTime dt = new DateTime(year, month, day); int era = tc.GetEra(dt); Assert.Equal(1, era); }
public void NegTest1() { System.Globalization.Calendar tc = new TaiwanCalendar(); Random rand = new Random(-55); int year = tc.MaxSupportedDateTime.Year - 1911 + rand.Next(1, Int32.MaxValue); int era = Calendar.CurrentEra; Assert.Throws <ArgumentOutOfRangeException>(() => { tc.GetDaysInMonth(year, era); }); }
public void NegTest4() { System.Globalization.Calendar tc = new TaiwanCalendar(); Random rand = new Random(-55); int year = rand.Next(tc.MinSupportedDateTime.Year, tc.MaxSupportedDateTime.Year + 1); int month = rand.Next(Int32.MinValue, 1); int era = Calendar.CurrentEra; Assert.Throws <ArgumentOutOfRangeException>(() => { tc.GetDaysInMonth(year, month, era); }); }
public void PosTest4() { System.Globalization.Calendar tc = new TaiwanCalendar(); DateTime dt = new DateTime(2000, 12, 31); int year = dt.Year; int month = dt.Month; int era; int actualDays; if (tc.IsLeapYear(year)) { actualDays = _DAYS_PER_MONTHS_IN_LEAP_YEAR[month]; } else { actualDays = _DAYS_PER_MONTHS_IN_NO_LEAP_YEAR[month]; } for (int i = 0; i < tc.Eras.Length; i++) { era = tc.Eras[i]; Assert.Equal(tc.GetDaysInMonth(year, month, era), actualDays); } }
public void PosTest1() { System.Globalization.Calendar tc = new TaiwanCalendar(); Random rand = new Random(-55); int year = rand.Next(tc.MinSupportedDateTime.Year, tc.MaxSupportedDateTime.Year - 1911); int month = rand.Next(1, 12); int era; int actualDays; if (tc.IsLeapYear(year)) { actualDays = _DAYS_PER_MONTHS_IN_LEAP_YEAR[month]; } else { actualDays = _DAYS_PER_MONTHS_IN_NO_LEAP_YEAR[month]; } for (int i = 0; i < tc.Eras.Length; i++) { era = tc.Eras[i]; Assert.Equal(tc.GetDaysInMonth(year, month, era), actualDays); } }