public static object DateTimeToJapaneseEraDateString(object date) { if (date == null || !(date is DateTime)) { return(null); } CultureInfo cultureInfo = new CultureInfo("ja-JP"); JapaneseCalendar calendar = new JapaneseCalendar(); cultureInfo.DateTimeFormat.Calendar = calendar; string text = ((DateTime)date).ToString("y.M.d", cultureInfo); switch (cultureInfo.DateTimeFormat.Calendar.GetEra((DateTime)date)) { case 1: text = "M" + text; break; case 2: text = "T" + text; break; case 3: text = "S" + text; break; case 4: text = "H" + text; break; } return(text); }
public void ToFourDigitYear(int year) { Calendar calendar = new JapaneseCalendar(); calendar.TwoDigitYearMax = 99; Assert.Equal(year, calendar.ToFourDigitYear(year)); }
public void TwoDigitYearMax_Set(int newTwoDigitYearMax) { Calendar calendar = new JapaneseCalendar(); calendar.TwoDigitYearMax = newTwoDigitYearMax; Assert.Equal(newTwoDigitYearMax, calendar.TwoDigitYearMax); }
public static void Main(string[] args) { //元号のリストを配列で定義 string[] eras = { "明治", "大正", "昭和", "平成" }; DateTime now = DateTime.Now; JapaneseCalendar jpn = new JapaneseCalendar(); //指定日時の元号を取得 int era = jpn.GetEra(now); //元号と年を出力 Console.WriteLine( "元号: {0} {1}年", eras[era - 1], jpn.GetYear(now) ); //日本のカルチャを作成 CultureInfo culture = new CultureInfo("ja-JP"); //カルチャのカレンダーを和暦に設定 culture.DateTimeFormat.Calendar = new JapaneseCalendar(); //ToStringで元号と年を出力 Console.WriteLine("ToStringでの出力: " + now.ToString("gg yy年", culture)); Console.ReadKey(); }
public static void JapaneseTest() { JapaneseCalendar jCal = new JapaneseCalendar(); DateTime dTest = jCal.ToDateTime(1, 1, 8, 0, 0, 0, 0, 4); Assert.Equal(dTest, new DateTime(1989, 1, 8)); }
public static void Main() { // Creates and initializes a JapaneseCalendar. JapaneseCalendar myCal = new JapaneseCalendar(); // Displays the header. Console.Write("YEAR\t"); for (int y = 1; y <= 5; y++) { Console.Write("\t{0}", y); } Console.WriteLine(); // Checks five years in the current era. Console.Write("CurrentEra:"); for (int y = 1; y <= 5; y++) { Console.Write("\t{0}", myCal.IsLeapYear(y, JapaneseCalendar.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 = 1; y <= 5; y++) { Console.Write("\t{0}", myCal.IsLeapYear(y, myCal.Eras[i])); } Console.WriteLine(); } }
public static void Main() { var jaJp = new CultureInfo("ja-JP"); var cal = new JapaneseCalendar(); jaJp.DateTimeFormat.Calendar = cal; string showaEra = "昭和"; var dt = cal.ToDateTime(65, 1, 9, 15, 0, 0, 0, GetEraIndex(showaEra)); FormattableString fmt = $"{dt:d}"; Console.WriteLine($"Japanese calendar date: {fmt.ToString(jaJp)}"); Console.WriteLine($"Gregorian calendar date: {fmt}"); int GetEraIndex(string eraName) { foreach (var ctr in cal.Eras) { if (jaJp.DateTimeFormat.GetEraName(ctr) == eraName) { return(ctr); } } return(0); } }
public static void Main() { var enUs = new CultureInfo("en-US"); var japaneseCal = new JapaneseCalendar(); var jaJp = new CultureInfo("ja-JP"); jaJp.DateTimeFormat.Calendar = japaneseCal; string heiseiEra = "平成"; var date = japaneseCal.ToDateTime(1, 8, 18, 0, 0, 0, 0, GetEraIndex(heiseiEra)); FormattableString fmt = $"{date:D}"; Console.WriteLine($"Japanese calendar date: {fmt.ToString(jaJp)} (Gregorian: {fmt.ToString(enUs)})"); int GetEraIndex(string eraName) { foreach (var ctr in japaneseCal.Eras) { if (jaJp.DateTimeFormat.GetEraName(ctr) == eraName) { return(ctr); } } return(0); } }
public void PosTest1() { DateTime actual = new JapaneseCalendar().MinSupportedDateTime; DateTime expected = new DateTime(1868, 9, 8); Assert.Equal(expected, actual); }
public static void Main() { var japaneseCal = new JapaneseCalendar(); var jaJp = new CultureInfo("ja-JP"); jaJp.DateTimeFormat.Calendar = japaneseCal; var date = new DateTime(1905, 2, 12); Console.WriteLine($"Gregorian calendar date: {date:d}"); // Call the ToString(IFormatProvider) method. Console.WriteLine($"Japanese calendar date: {date.ToString("d", jaJp)}"); // Use a FormattableString object. FormattableString fmt = $"{date:d}"; Console.WriteLine($"Japanese calendar date: {fmt.ToString(jaJp)}"); // Use the JapaneseCalendar object. Console.WriteLine($"Japanese calendar date: {jaJp.DateTimeFormat.GetEraName(japaneseCal.GetEra(date))}" + $"{japaneseCal.GetYear(date)}/{japaneseCal.GetMonth(date)}/{japaneseCal.GetDayOfMonth(date)}"); // Use the current culture. CultureInfo.CurrentCulture = jaJp; Console.WriteLine($"Japanese calendar date: {date:d}"); }
public void PosTest1() { int[] actual = new JapaneseCalendar().Eras; Assert.NotNull(actual); Assert.Equal(c_EXPECTED_ERAS.Length, actual.Length); Assert.Equal(c_EXPECTED_ERAS, actual); }
public void PosTest1() { DateTime actual = new JapaneseCalendar().MaxSupportedDateTime; DateTime expected = DateTime.MaxValue; Assert.Equal(expected, actual); }
public void PosTest1() { int actual = new JapaneseCalendar().TwoDigitYearMax; int expected = 99; Assert.Equal(expected, actual); }
public static bool CreateCalendar(string calendarName, out Calendar calendar) { calendar = null; bool result = false; if (Validator.CompareWithInvariantCulture(calendarName, "Gregorian Arabic")) { result = true; calendar = new GregorianCalendar(GregorianCalendarTypes.Arabic); } else if (Validator.CompareWithInvariantCulture(calendarName, "Gregorian Middle East French")) { result = true; calendar = new GregorianCalendar(GregorianCalendarTypes.MiddleEastFrench); } else if (Validator.CompareWithInvariantCulture(calendarName, "Gregorian Transliterated English")) { result = true; calendar = new GregorianCalendar(GregorianCalendarTypes.TransliteratedEnglish); } else if (Validator.CompareWithInvariantCulture(calendarName, "Gregorian Transliterated French")) { result = true; calendar = new GregorianCalendar(GregorianCalendarTypes.TransliteratedFrench); } else if (Validator.CompareWithInvariantCulture(calendarName, "Gregorian US English")) { result = true; calendar = new GregorianCalendar(GregorianCalendarTypes.USEnglish); } else if (Validator.CompareWithInvariantCulture(calendarName, "Hebrew")) { calendar = new HebrewCalendar(); } else if (Validator.CompareWithInvariantCulture(calendarName, "Hijri")) { calendar = new HijriCalendar(); } else if (Validator.CompareWithInvariantCulture(calendarName, "Japanese")) { calendar = new JapaneseCalendar(); } else if (Validator.CompareWithInvariantCulture(calendarName, "Korea")) { calendar = new KoreanCalendar(); } else if (Validator.CompareWithInvariantCulture(calendarName, "Taiwan")) { calendar = new TaiwanCalendar(); } else if (Validator.CompareWithInvariantCulture(calendarName, "Thai Buddhist")) { calendar = new ThaiBuddhistCalendar(); } else if (Validator.CompareWithInvariantCulture(calendarName, "Gregorian")) { calendar = new GregorianCalendar(); } return(result); }
public void TwoDigitYearMax_Set() { Calendar calendar = new JapaneseCalendar(); int newTwoDigitYearMax = 200; calendar.TwoDigitYearMax = newTwoDigitYearMax; Assert.Equal(newTwoDigitYearMax, calendar.TwoDigitYearMax); }
public static void Main() { // Creates and initializes a JapaneseCalendar. JapaneseCalendar myCal = new JapaneseCalendar(); // Displays the header. Console.Write("YEAR\t"); for (int y = 1; y <= 5; y++) { Console.Write("\t{0}", y); } Console.WriteLine(); // Displays the value of the CurrentEra property. Console.Write("CurrentEra:"); for (int y = 1; y <= 5; y++) { Console.Write("\t{0}", myCal.GetDaysInYear(y, JapaneseCalendar.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 = 1; y <= 5; y++) { Console.Write("\t{0}", myCal.GetDaysInYear(y, myCal.Eras[i])); } Console.WriteLine(); } }
public void PosTest3() { System.Globalization.Calendar calendar = new JapaneseCalendar(); VerificationHelper(calendar, new DateTime(2006, 10, 31), 1, new DateTime(2006, 11, 30)); VerificationHelper(calendar, new DateTime(2006, 12, 31), -1, new DateTime(2006, 11, 30)); }
static void Main() { var cal = new JapaneseCalendar(); var jaJp = new CultureInfo("ja-JP"); jaJp.DateTimeFormat.Calendar = cal; var date1 = cal.ToDateTime(2, 1, 1, 0, 0, 0, 0, JapaneseCalendar.CurrentEra); Console.WriteLine($"Japanese calendar date: {date1.ToString("D", jaJp)}, " + $"Gregorian calendar date: {date1.ToString("D", CultureInfo.InvariantCulture)}"); var date2 = cal.ToDateTime(6, 11, 7, 0, 0, 0, 0, GetEraIndex("大正")); Console.WriteLine($"Japanese calendar date: {date2.ToString("D", jaJp)}, " + $"Gregorian calendar date: {date2.ToString("D", CultureInfo.InvariantCulture)}"); int GetEraIndex(string eraName) { foreach (var ctr in cal.Eras) { if (jaJp.DateTimeFormat.GetEraName(ctr) == eraName) { return(ctr); } } return(0); } }
private void Form1_Load(object sender, EventArgs e) { JapaneseCalendar jc = new JapaneseCalendar(); //Thread.CurrentThread.CurrentCulture=; CultureInfo ci1 = Thread.CurrentThread.CurrentUICulture; int i = 1; string strI = i.ToString("C", new CultureInfo("de-DE")); }
[InlineData("2019-12-31", 5)] // Reiwa public void VerifyEraIds(string date, int expectedEra) { var calendar = new JapaneseCalendar(); var time = DateTime.Parse(date); int era = calendar.GetEra(time); Assert.Equal(expectedEra, era); }
// Summary: // Returns the era in the specified System.DateTime. // // Parameters: // date: // The System.DateTime to read. // // Returns: // The name of EraYear public static string GetEraYear(DateTime?date) { if (date.HasValue) { JapaneseCalendar japaneseCalendar = new JapaneseCalendar(); return(((EraName)japaneseCalendar.GetEra(date.Value)).GetEnumDescription()); } return(string.Empty); }
static void Main(string[] args) { // BAD: hard-coded era start date var henseiStart = new DateTime(1989, 1, 8); // BAD: hard-coded era start dates, list List <DateTime> listOfEraStart = new List <DateTime> { new DateTime(1989, 1, 8) }; // BAD: hardcoded era name string currentEra = "Heisei"; DateTimeOffset dateNow = DateTimeOffset.Now; DateTimeOffset dateThisEra = new DateTimeOffset(1989, 1, 8, 0, 0, 0, 0, TimeSpan.Zero); CultureInfo japaneseCulture = CultureInfo.GetCultureInfo("ja-JP"); JapaneseCalendar jk = new JapaneseCalendar(); // BAD: datetime is created from constant year in the current era, and the result will change with era change var datejkCurrentEra = jk.ToDateTime(32, 2, 1, 9, 9, 9, 9); Console.WriteLine("Date for datejkCurrentEra {0} and year {1}", datejkCurrentEra.ToString(japaneseCulture), jk.GetYear(datejkCurrentEra)); // BAD: datetime is created from constant year in the current era, and the result will change with era change var datejk = jk.ToDateTime(32, 2, 1, 9, 9, 9, 9, 0); Console.WriteLine("Date for jk {0} and year {1}", datejk.ToString(japaneseCulture), jk.GetYear(datejk)); // OK: datetime is created from constant year in the specific era, and the result will not change with era change var datejk1 = jk.ToDateTime(32, 2, 1, 9, 9, 9, 9, 4); Console.WriteLine("Date for jk {0} and year {1}", datejk1.ToString(japaneseCulture), jk.GetYear(datejk1)); // OK: year is not hard-coded, i.e. it may be updated var datejk0 = jk.ToDateTime(jk.GetYear(datejk), 2, 1, 9, 9, 9, 9); Console.WriteLine("Date for jk0 {0} and year {1}", datejk0, jk.GetYear(datejk0)); // BAD: hard-coded year conversion int realYear = 1988 + jk.GetYear(datejk); Console.WriteLine("Which converts to year {0}", realYear); // BAD: creating DateTime using specified Japanese era date. This may yield a different date when era changes DateTime val = new DateTime(32, 2, 1, new JapaneseCalendar()); Console.WriteLine("DateTime from constructor {0}", val); // OK: variable data for Year, not necessarily hard-coded and can come from adjusted source DateTime val1 = new DateTime(jk.GetYear(datejk), 2, 1, new JapaneseCalendar()); Console.WriteLine("DateTime from constructor {0}", val); }
public void PosTest2() { int expected = 200; System.Globalization.Calendar calendar = new JapaneseCalendar(); calendar.TwoDigitYearMax = expected; int actual = calendar.TwoDigitYearMax; Assert.Equal(expected, actual); }
public static void Main() { var cal = new JapaneseCalendar(); // constructing date using current era var dat = cal.ToDateTime(2, 1, 2, 0, 0, 0, 0); Console.WriteLine($"{dat:s}"); // constructing date using current era dat = new DateTime(2, 1, 2, cal); Console.WriteLine($"{dat:s}"); }
[InlineData("2019-12-31", "令和")] // Reiwa public void VerifyEraNames(string date, string expectedEra) { CultureInfo japaneseCulture = new CultureInfo("ja-JP"); var calendar = new JapaneseCalendar(); japaneseCulture.DateTimeFormat.Calendar = calendar; var eraTime = DateTime.Parse(date); Assert.Equal(expectedEra, eraTime.ToString("gg", japaneseCulture)); }
public static void Main() { // Creates and initializes a JapaneseCalendar. JapaneseCalendar myCal = new JapaneseCalendar(); // Displays the values in the Eras property. for (int i = 0; i < myCal.Eras.Length; i++) { Console.WriteLine("Eras[{0}] = {1}", i, myCal.Eras[i]); } }
public void PosTest2() { System.Globalization.Calendar calendar = new JapaneseCalendar(); VerificationHelper(calendar, new DateTime(1868, 9, 8), 1, new DateTime(1868, 10, 8)); VerificationHelper(calendar, new DateTime(1868, 10, 8), -1, new DateTime(1868, 9, 8)); VerificationHelper(calendar, new DateTime(9999, 11, 30), 1, new DateTime(9999, 12, 30)); VerificationHelper(calendar, new DateTime(9999, 12, 30), -1, new DateTime(9999, 11, 30)); VerificationHelper(calendar, DateTime.MaxValue, 0, DateTime.MaxValue); VerificationHelper(calendar, new DateTime(1868, 9, 8), 0, new DateTime(1868, 9, 8)); }
public static object DateTimeToJapaneseEraDateString(object date, string format) { if (date == null || !(date is DateTime)) { return(null); } CultureInfo cultureInfo = new CultureInfo("ja-JP"); JapaneseCalendar calendar = new JapaneseCalendar(); cultureInfo.DateTimeFormat.Calendar = calendar; return(((DateTime)date).ToString(format, cultureInfo)); }
public static object StringToJapaneseEraDateString(object p_objDate) { if (Tools.AnyToString(p_objDate) == string.Empty) { return(p_objDate); } CultureInfo cultureInfo = new CultureInfo("ja-JP"); JapaneseCalendar calendar = new JapaneseCalendar(); cultureInfo.DateTimeFormat.Calendar = calendar; return(DateTime.Parse((string)p_objDate, cultureInfo)); }
public static Calendar CalendarFromString( string name ) { Calendar c; if (name == null) { name = String.Empty; } switch (name.ToLower()) { case "hebrew": c = new HebrewCalendar(); break; case "hijri": c = new HijriCalendar(); break; case "japanese": c = new JapaneseCalendar(); break; case "korean": c = new KoreanCalendar(); break; case "taiwan": c = new TaiwanCalendar(); break; case "thaibuddhist": c = new ThaiBuddhistCalendar(); break; case "umalqura": c = new UmAlQuraCalendar(); break; #if !SILVERLIGHT case "persian": c = new PersianCalendar(); break; #endif default: c = new GregorianCalendar(); break; } return(c); }
public static void Main() { var japaneseCal = new JapaneseCalendar(); var jaJp = new CultureInfo("ja-JP"); jaJp.DateTimeFormat.Calendar = japaneseCal; var date = new DateTime(2, 1, 1, japaneseCal); Console.WriteLine($"Gregorian calendar date: {date:d}"); Console.WriteLine($"Japanese calendar date: {date.ToString("d", jaJp)}"); }
public static void JapaneseTest() { JapaneseCalendar jCal = new JapaneseCalendar(); DateTime dTest = jCal.ToDateTime(1, 1, 8, 0, 0, 0, 0); Assert.Equal(dTest, new DateTime(1989, 1, 8)); }
public bool runTest() { Console.WriteLine(s_strTFPath + "\\" + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer); String strLoc = "Loc_000oo"; String strValue = String.Empty; int iCountErrors = 0; int iCountTestcases = 0; try { DateTime dTest; HebrewCalendar hCal = new HebrewCalendar(); JulianCalendar jCal = new JulianCalendar(); HijriCalendar hiCal = new HijriCalendar (); GregorianCalendar gCal = new GregorianCalendar (); JapaneseCalendar jaCal = new JapaneseCalendar (); KoreanCalendar kCal = new KoreanCalendar (); ThaiBuddhistCalendar tCal = new ThaiBuddhistCalendar (); strLoc = "Loc_100vy"; iCountTestcases++; dTest = new DateTime(5360,04,14,hCal); if (dTest.Year != 1600) { ++iCountErrors; printerr( "Error_100aa! DateTime object was not set correctly"); } if (dTest.Month != 1) { ++iCountErrors; printerr( "Error_100bb! DateTime object was not set correctly"); } if (dTest.Day != 1) { ++iCountErrors; printerr( "Error_100cc! DateTime object was not set correctly"); } if (dTest.Hour != 0) { ++iCountErrors; printerr( "Error_100dd! DateTime object was not set correctly"); } if (dTest.Minute != 0) { ++iCountErrors; printerr( "Error_100ee! DateTime object was not set correctly"); } if (dTest.Second != 0) { ++iCountErrors; printerr( "Error_100ff! DateTime object was not set correctly"); } if (dTest.Millisecond != 0) { ++iCountErrors; printerr( "Error_100gg! DateTime object was not set correctly"); } strLoc = "Loc_101vy"; iCountTestcases++; dTest = new DateTime(1599,12,22,jCal); if (dTest.Year != 1600) { ++iCountErrors; printerr( "Error_101aa! DateTime object was not set correctly"); } if (dTest.Month != 1) { ++iCountErrors; printerr( "Error_101bb! DateTime object was not set correctly"); } if (dTest.Day != 1) { ++iCountErrors; printerr( "Error_101cc! DateTime object was not set correctly"); } if (dTest.Hour != 0) { ++iCountErrors; printerr( "Error_101dd! DateTime object was not set correctly"); } if (dTest.Minute != 0) { ++iCountErrors; printerr( "Error_101ee! DateTime object was not set correctly"); } if (dTest.Second != 0) { ++iCountErrors; printerr( "Error_101ff! DateTime object was not set correctly"); } if (dTest.Millisecond != 0) { ++iCountErrors; printerr( "Error_101gg! DateTime object was not set correctly"); } strLoc = "Loc_102vy"; iCountTestcases++; dTest = new DateTime(1008,06,15,hiCal); if (dTest.Year != 1600) { ++iCountErrors; printerr( "Error_102aa! DateTime object was not set correctly"); } if (dTest.Month != 1) { ++iCountErrors; printerr( "Error_102bb! DateTime object was not set correctly"); } if (dTest.Day != 1) { ++iCountErrors; printerr( "Error_102cc! DateTime object was not set correctly"); } if (dTest.Hour != 0) { ++iCountErrors; printerr( "Error_102dd! DateTime object was not set correctly"); } if (dTest.Minute != 0) { ++iCountErrors; printerr( "Error_102ee! DateTime object was not set correctly"); } if (dTest.Second != 0) { ++iCountErrors; printerr( "Error_102ff! DateTime object was not set correctly"); } if (dTest.Millisecond != 0) { ++iCountErrors; printerr( "Error_102gg! DateTime object was not set correctly"); } strLoc = "Loc_103vy"; iCountTestcases++; dTest = new DateTime(1600,1,1,gCal); if (dTest.Year != 1600) { ++iCountErrors; printerr( "Error_103aa! DateTime object was not set correctly"); } if (dTest.Month != 1) { ++iCountErrors; printerr( "Error_103bb! DateTime object was not set correctly"); } if (dTest.Day != 1) { ++iCountErrors; printerr( "Error_103cc! DateTime object was not set correctly"); } if (dTest.Hour != 0) { ++iCountErrors; printerr( "Error_103dd! DateTime object was not set correctly"); } if (dTest.Minute != 0) { ++iCountErrors; printerr( "Error_103ee! DateTime object was not set correctly"); } if (dTest.Second != 0) { ++iCountErrors; printerr( "Error_103ff! DateTime object was not set correctly"); } if (dTest.Millisecond != 0) { ++iCountErrors; printerr( "Error_103gg! DateTime object was not set correctly"); } strLoc = "Loc_104vy"; iCountTestcases++; dTest = new DateTime(1,1,8,jaCal); if (dTest.Year != 1989) { ++iCountErrors; printerr( "Error_104aa! DateTime object was not set correctly"); } if (dTest.Month != 1) { ++iCountErrors; printerr( "Error_104bb! DateTime object was not set correctly"); } if (dTest.Day != 8) { ++iCountErrors; printerr( "Error_104cc! DateTime object was not set correctly"); } if (dTest.Hour != 0) { ++iCountErrors; printerr( "Error_104dd! DateTime object was not set correctly"); } if (dTest.Minute != 0) { ++iCountErrors; printerr( "Error_104ee! DateTime object was not set correctly"); } if (dTest.Second != 0) { ++iCountErrors; printerr( "Error_104ff! DateTime object was not set correctly"); } if (dTest.Millisecond != 0) { ++iCountErrors; printerr( "Error_104gg! DateTime object was not set correctly"); } strLoc = "Loc_105vy"; iCountTestcases++; dTest = new DateTime(3933,1,1,kCal); if (dTest.Year != 1600) { ++iCountErrors; printerr( "Error_105aa! DateTime object was not set correctly"); } if (dTest.Month != 1) { ++iCountErrors; printerr( "Error_105bb! DateTime object was not set correctly"); } if (dTest.Day != 1) { ++iCountErrors; printerr( "Error_105cc! DateTime object was not set correctly"); } if (dTest.Hour != 0) { ++iCountErrors; printerr( "Error_105dd! DateTime object was not set correctly"); } if (dTest.Minute != 0) { ++iCountErrors; printerr( "Error_105ee! DateTime object was not set correctly"); } if (dTest.Second != 0) { ++iCountErrors; printerr( "Error_105ff! DateTime object was not set correctly"); } if (dTest.Millisecond != 0) { ++iCountErrors; printerr( "Error_105gg! DateTime object was not set correctly"); } strLoc = "Loc_106vy"; iCountTestcases++; dTest = new DateTime(2143,1,1,tCal); if (dTest.Year != 1600) { ++iCountErrors; printerr( "Error_106aa! DateTime object was not set correctly"); } if (dTest.Month != 1) { ++iCountErrors; printerr( "Error_106bb! DateTime object was not set correctly"); } if (dTest.Day != 1) { ++iCountErrors; printerr( "Error_106cc! DateTime object was not set correctly"); } if (dTest.Hour != 0) { ++iCountErrors; printerr( "Error_106dd! DateTime object was not set correctly"); } if (dTest.Minute != 0) { ++iCountErrors; printerr( "Error_106ee! DateTime object was not set correctly"); } if (dTest.Second != 0) { ++iCountErrors; printerr( "Error_106ff! DateTime object was not set correctly"); } if (dTest.Millisecond != 0) { ++iCountErrors; printerr( "Error_106gg! DateTime object was not set correctly"); } strLoc = "Loc_524vy"; iCountTestcases++; try { dTest = new DateTime(0,03,25,hCal); iCountErrors++; printerr( "Error_200bb! No exception thrown"); } catch (ArgumentOutOfRangeException argexc) { printinfo( "Info_512ad! Caught ArguementOutOfRangeException"); } catch (Exception e) { ++iCountErrors; printerr( "Error_200aa! Wrong exception thrown: " + e.ToString()); } strLoc = "Loc_333vy"; iCountTestcases++; try { dTest = new DateTime(10000,03,25,hCal); iCountErrors++; printerr( "Error_300bb! No exception thrown"); } catch (ArgumentOutOfRangeException argexc) { printinfo( "Info_333ad! Caught ArguementOutOfRangeException"); } catch (Exception e) { ++iCountErrors; printerr( "Error_300aa! Wrong exception thrown: " + e.ToString()); } strLoc = "Loc_444vy"; iCountTestcases++; try { dTest = new DateTime(5000,0,25,hCal); iCountErrors++; printerr( "Error_400bb! No exception thrown"); } catch (ArgumentOutOfRangeException argexc) { printinfo( "Info_444ad! Caught ArguementOutOfRangeException"); } catch (Exception e) { ++iCountErrors; printerr( "Error_400aa! Wrong exception thrown: " + e.ToString()); } strLoc = "Loc_555vy"; iCountTestcases++; try { dTest = new DateTime(5000,13,25,jCal); iCountErrors++; printerr( "Error_500bb! No exception thrown"); } catch (ArgumentOutOfRangeException argexc) { printinfo( "Info_555ad! Caught ArguementOutOfRangeException"); } catch (Exception e) { ++iCountErrors; printerr( "Error_500aa! Wrong exception thrown: " + e.ToString()); } strLoc = "Loc_665vy"; iCountTestcases++; try { dTest = new DateTime(2000,03,0,jCal); iCountErrors++; printerr( "Error_600bb! No exception thrown"); } catch (ArgumentOutOfRangeException argexc) { printinfo( "Info_665ad! Caught ArguementOutOfRangeException"); } catch (Exception e) { ++iCountErrors; printerr( "Error_600aa! Wrong exception thrown: " + e.ToString()); } strLoc = "Loc_777vy"; iCountTestcases++; try { dTest = new DateTime(2000,03,32,jCal); iCountErrors++; printerr( "Error_700bb! No exception thrown"); } catch (ArgumentOutOfRangeException argexc) { printinfo( "Info_775ad! Caught ArguementOutOfRangeException"); } catch (Exception e) { ++iCountErrors; printerr( "Error_700aa! Wrong exception thrown: " + e.ToString()); } strLoc = "Loc_888vy"; iCountTestcases++; try { dTest = new DateTime(2000,03,14,null); iCountErrors++; printerr( "Error_800bb! No exception thrown"); } catch (ArgumentNullException argexc) { printinfo( "Info_885ad! Caught ArguementNullException"); } catch (Exception e) { ++iCountErrors; printerr( "Error_800aa! Wrong exception thrown: " + e.ToString()); } } catch (Exception exc_general ) { ++iCountErrors; Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy! strLoc=="+ strLoc +", exc_general=="+exc_general.ToString()); } if ( iCountErrors == 0 ) { Console.WriteLine( "paSs. "+s_strTFName+" ,iCountTestcases=="+iCountTestcases.ToString()); return true; } else { Console.WriteLine("FAiL! "+s_strTFName+" ,iCountErrors=="+iCountErrors.ToString()+" , BugNums?: "+s_strActiveBugNums ); return false; } }
public static void JapaneseTest() { JapaneseCalendar cal = new JapaneseCalendar(); Assert.True(cal.Eras.Length >= 4); }