public void TestJapaneseYear3282() { IBM.ICU.Util.Calendar c = IBM.ICU.Util.Calendar.GetInstance(IBM.ICU.Util.ULocale.ENGLISH); c.Set(2003, IBM.ICU.Util.Calendar.SEPTEMBER, 25); IBM.ICU.Util.JapaneseCalendar jcal = new IBM.ICU.Util.JapaneseCalendar(); // jcal.setTime(new Date(1187906308151L)); alternate value jcal.SetTime(c.GetTime()); Logln("Now is: " + jcal.GetTime()); c.SetTime(jcal.GetTime()); int nowYear = c.Get(IBM.ICU.Util.Calendar.YEAR); Logln("Now year: " + nowYear); SimpleDateFormat jdf = (SimpleDateFormat)IBM.ICU.Text.DateFormat .GetDateInstance(jcal, IBM.ICU.Text.DateFormat.DEFAULT, ILOG.J2CsMapping.Util.Locale.GetDefault()); jdf.ApplyPattern("G yy/MM/dd"); String text = jdf.Format(jcal.GetTime()); Logln("Now is: " + text + " (in Japan)"); try { DateTime date = jdf.Parse(text); Logln("But is this not the date?: " + date); c.SetTime(date); int thenYear = c.Get(IBM.ICU.Util.Calendar.YEAR); Logln("Then year: " + thenYear); if (thenYear != nowYear) { Errln("Nowyear " + nowYear + " is not thenyear " + thenYear); } else { Logln("Nowyear " + nowYear + " == thenyear " + thenYear); } } catch (ILOG.J2CsMapping.Util.ParseException ex) { Console.Error.WriteLine(ex.StackTrace); } }
public void Test3860() { ULocale loc = new ULocale("ja_JP@calendar=japanese"); IBM.ICU.Util.Calendar cal = new IBM.ICU.Util.JapaneseCalendar(loc); DateFormat enjformat = cal.GetDateTimeFormat(0, 0, new ULocale( "en_JP@calendar=japanese")); DateFormat format = cal.GetDateTimeFormat(0, 0, loc); ((SimpleDateFormat)format).ApplyPattern("y.M.d"); // Note: just 'y' // doesn't work here. ILOG.J2CsMapping.Text.ParsePosition pos = new ILOG.J2CsMapping.Text.ParsePosition(0); DateTime aDate = format.Parse("1.1.9", pos); // after the start of heisei // accession. Jan 1, 1H // wouldn't work because it is // actually showa 64 String inEn = enjformat.Format(aDate); cal.Clear(); cal.SetTime(aDate); int gotYear = cal.Get(IBM.ICU.Util.Calendar.YEAR); int gotEra = cal.Get(IBM.ICU.Util.Calendar.ERA); int expectYear = 1; int expectEra = IBM.ICU.Util.JapaneseCalendar.CURRENT_ERA; if ((gotYear != expectYear) || (gotEra != expectEra)) { Errln("Expected year " + expectYear + ", era " + expectEra + ", but got year " + gotYear + " and era " + gotEra + ", == " + inEn); } else { Logln("Got year " + gotYear + " and era " + gotEra + ", == " + inEn); } }