From 98385235ac186618e6182837e9e5f01c020ef8e6 Mon Sep 17 00:00:00 2001 From: "Steven R. Loomis" Date: Sat, 26 Aug 2006 04:15:17 +0000 Subject: [PATCH] ICU-5345 fix Japanese Calendar and tests X-SVN-Rev: 20170 --- .../icu/dev/test/calendar/JapaneseTest.java | 130 +++++++++++++++++- icu4j/src/com/ibm/icu/util/Calendar.java | 40 +++++- .../com/ibm/icu/util/JapaneseCalendar.java | 52 ++++++- 3 files changed, 215 insertions(+), 7 deletions(-) diff --git a/icu4j/src/com/ibm/icu/dev/test/calendar/JapaneseTest.java b/icu4j/src/com/ibm/icu/dev/test/calendar/JapaneseTest.java index 022759922b5..e7e0d26621b 100644 --- a/icu4j/src/com/ibm/icu/dev/test/calendar/JapaneseTest.java +++ b/icu4j/src/com/ibm/icu/dev/test/calendar/JapaneseTest.java @@ -1,6 +1,6 @@ /* ******************************************************************************* - * Copyright (C) 2002-2005, International Business Machines Corporation and * + * Copyright (C) 2002-2006, International Business Machines Corporation and * * others. All Rights Reserved. * ******************************************************************************* */ @@ -19,7 +19,7 @@ import com.ibm.icu.text.SimpleDateFormat; import com.ibm.icu.util.ULocale; /** - * Tests for the IslamicCalendar class. + * Tests for the JapaneseCalendar class. */ public class JapaneseTest extends CalendarTest { public static void main(String args[]) throws Exception { @@ -166,5 +166,131 @@ public class JapaneseTest extends CalendarTest { logln("Got year " + gotYear + " and era " + gotEra + ", == " + inEn); } } + + public void Test5345parse() { + // Test parse with incomplete information + DateFormat fmt2= DateFormat.getDateInstance(); //DateFormat.LONG, Locale.US); + JapaneseCalendar c = new JapaneseCalendar(TimeZone.getDefault(), new ULocale("en_US")); + SimpleDateFormat fmt = (SimpleDateFormat)c.getDateTimeFormat(1,1,new ULocale("en_US@calendar=japanese")); + fmt.applyPattern("G y"); + logln("fmt's locale = " + fmt.getLocale(ULocale.ACTUAL_LOCALE)); + //SimpleDateFormat fmt = new SimpleDateFormat("G y", new Locale("en_US@calendar=japanese")); + long aDateLong = -3197120400000L + + 3600000L; // compensate for DST + Date aDate = new Date(aDateLong); //08 Sept 1868 + logln("aDate: " + aDate.toString() +", from " + aDateLong); + String str; + str = fmt2.format(aDate); + logln("Test Date: " + str); + str = fmt.format(aDate); + logln("as Japanese Calendar: " + str); + String expected = "Meiji 1"; + if(!str.equals(expected)) { + errln("FAIL: Expected " + expected + " but got " + str); + } + Date otherDate; + try { + otherDate = fmt.parse(expected); + if(!otherDate.equals(aDate)) { + String str3; + // ParsePosition pp; + Date dd = fmt.parse(expected); + str3 = fmt.format(otherDate); + long oLong = otherDate.getTime(); + long aLong = otherDate.getTime(); + + errln("FAIL: Parse incorrect of " + expected + ": wanted " + aDate + " ("+aLong+"), but got " + " " + + otherDate + " ("+oLong+") = " + str3 + " not " + dd.toString() ); + + + } else { + logln("Parsed OK: " + expected); + } + } catch(java.text.ParseException pe) { + errln("FAIL: ParseException: " + pe.toString()); + pe.printStackTrace(); + } + } + + + private void checkExpected(Calendar c, int expected[] ) { + final String[] FIELD_NAME = { + "ERA", "YEAR", "MONTH", "WEEK_OF_YEAR", "WEEK_OF_MONTH", + "DAY_OF_MONTH", "DAY_OF_YEAR", "DAY_OF_WEEK", + "DAY_OF_WEEK_IN_MONTH", "AM_PM", "HOUR", "HOUR_OF_DAY", + "MINUTE", "SECOND", "MILLISECOND", "ZONE_OFFSET", + "DST_OFFSET", "YEAR_WOY", "DOW_LOCAL", "EXTENDED_YEAR", + "JULIAN_DAY", "MILLISECONDS_IN_DAY", + }; + + for(int i= 0;i