ICU-7623 Merged the fix for ticket#7644 (r27978) from trunk to maint-4-4. Added the ticket number in readme.html for ICU4J 4.4.1 release.
X-SVN-Rev: 27979
diff --git a/main/classes/core/src/com/ibm/icu/text/DateIntervalFormat.java b/main/classes/core/src/com/ibm/icu/text/DateIntervalFormat.java
index 5578bf9..572ecdb 100644
--- a/main/classes/core/src/com/ibm/icu/text/DateIntervalFormat.java
+++ b/main/classes/core/src/com/ibm/icu/text/DateIntervalFormat.java
@@ -26,8 +26,7 @@
/**
* DateIntervalFormat is a class for formatting and parsing date
* intervals in a language-independent manner.
- * Date interval formatting is supported in Gregorian calendar only.
- * And only formatting is supported. Parsing is not supported.
+ * Only formatting is supported. Parsing is not supported.
*
* <P>
* Date interval means from one date to another date,
@@ -593,7 +592,7 @@
* @param pos On input: an alignment field, if desired.
* On output: the offsets of the alignment field.
* @return Reference to 'appendTo' parameter.
- * @throws IllegalArgumentException if the two calendars are not equivalent, or the calendars are not Gregorian calendar.
+ * @throws IllegalArgumentException if the two calendars are not equivalent.
* @stable ICU 4.0
*/
public final StringBuffer format(Calendar fromCalendar,
@@ -602,9 +601,8 @@
FieldPosition pos)
{
// not support different calendar types and time zones
- if ( !fromCalendar.isEquivalentTo(toCalendar) ||
- !fromCalendar.getType().equals("gregorian") ) {
- throw new IllegalArgumentException("can not format on two different calendars or non-Gregorian calendars");
+ if ( !fromCalendar.isEquivalentTo(toCalendar) ) {
+ throw new IllegalArgumentException("can not format on two different calendars");
}
// First, find the largest different calendar field.
diff --git a/main/classes/core/src/com/ibm/icu/text/DateIntervalInfo.java b/main/classes/core/src/com/ibm/icu/text/DateIntervalInfo.java
index e28a22f..f3bd62c 100644
--- a/main/classes/core/src/com/ibm/icu/text/DateIntervalInfo.java
+++ b/main/classes/core/src/com/ibm/icu/text/DateIntervalInfo.java
@@ -138,7 +138,8 @@
* <P>
* DateIntervalInfo are not expected to be subclassed.
* Data for a calendar is loaded out of resource bundles.
- * To ICU 4.0, date interval patterns are only supported in Gregorian calendar.
+ * Through ICU 4.4, date interval patterns are only supported in the Gregoria
+ * calendar; non-Gregorian calendars are supported from ICU 4.4.1.
*
* @stable ICU 4.0
*/
@@ -303,8 +304,9 @@
/**
* Construct DateIntervalInfo for the given locale,
- * @param locale the interval patterns are loaded from the Gregorian
- * calendar data in this locale.
+ * @param locale the interval patterns are loaded from the appropriate
+ * calendar data (specified calendar or default calendar)
+ * in this locale.
* @stable ICU 4.0
*/
public DateIntervalInfo(ULocale locale)
@@ -362,6 +364,15 @@
// loop through all locales to get all available skeletons'
// interval format
ULocale parentLocale = locale;
+ // Get the correct calendar type
+ String calendarTypeToUse = locale.getKeywordValue("calendar");
+ if ( calendarTypeToUse == null ) {
+ String[] preferredCalendarTypes = Calendar.getKeywordValuesForLocale("calendar", locale, true);
+ calendarTypeToUse = preferredCalendarTypes[0]; // the most preferred calendar
+ }
+ if ( calendarTypeToUse == null ) {
+ calendarTypeToUse = "gregorian"; // fallback
+ }
do {
String name = parentLocale.getName();
if ( name.length() == 0 ) {
@@ -371,9 +382,9 @@
ICUResourceBundle rb = (ICUResourceBundle) UResourceBundle.
getBundleInstance(ICUResourceBundle.ICU_BASE_NAME,locale);
rb = rb.getWithFallback("calendar");
- ICUResourceBundle gregorianBundle = rb.getWithFallback(
- "gregorian");
- ICUResourceBundle itvDtPtnResource =gregorianBundle.
+ ICUResourceBundle calTypeBundle = rb.getWithFallback(
+ calendarTypeToUse);
+ ICUResourceBundle itvDtPtnResource =calTypeBundle.
getWithFallback("intervalFormats");
// look for fallback first, since it establishes the default order
String fallback = itvDtPtnResource.getStringWithFallback(
diff --git a/main/tests/core/src/com/ibm/icu/dev/test/format/DateIntervalFormatTest.java b/main/tests/core/src/com/ibm/icu/dev/test/format/DateIntervalFormatTest.java
index a9c1705..3f4b37f 100644
--- a/main/tests/core/src/com/ibm/icu/dev/test/format/DateIntervalFormatTest.java
+++ b/main/tests/core/src/com/ibm/icu/dev/test/format/DateIntervalFormatTest.java
@@ -623,6 +623,51 @@
"de", "2007 01 10 10:10:10", "2007 01 10 10:10:20", "hv", "10 vorm. Vereinigte Staaten (Los Angeles)",
"de", "2007 01 10 10:10:10", "2007 01 10 10:10:20", "hz", "10 vorm. GMT-08:00",
+
+ // Thai (default calendar buddhist)
+
+ "th", "2550 10 10 10:10:10", "2551 10 10 10:10:10", "EEEEdMMMy", "\\u0E27\\u0E31\\u0E19\\u0E1E\\u0E38\\u0E18 10 \\u0E15.\\u0E04. 2550 \\u2013 \\u0E27\\u0E31\\u0E19\\u0E28\\u0E38\\u0E01\\u0E23\\u0E4C 10 \\u0E15.\\u0E04. 2551",
+
+
+ "th", "2550 10 10 10:10:10", "2551 10 10 10:10:10", "dMMM", "10 \\u0E15.\\u0E04. 2550 \\u2013 10 \\u0E15.\\u0E04. 2551",
+
+ "th", "2550 10 10 10:10:10", "2551 10 10 10:10:10", "MMMy", "\\u0E15.\\u0E04. 2550 - \\u0E15.\\u0E04. 2551",
+
+
+ "th", "2550 10 10 10:10:10", "2551 10 10 10:10:10", "EdMy", "\\u0E1E. 10/10/50 \\u2013 \\u0E28. 10/10/51",
+
+ "th", "2550 10 10 10:10:10", "2551 10 10 10:10:10", "dMy", "10/10/50 \\u2013 10/10/51",
+
+
+ "th", "2550 10 10 10:10:10", "2551 10 10 10:10:10", "My", "10/50 \\u2013 10/51",
+
+ "th", "2550 10 10 10:10:10", "2551 10 10 10:10:10", "EdM", "\\u0E1E. 10/10/50 \\u2013 \\u0E28. 10/10/51",
+
+
+ "th", "2550 10 10 10:10:10", "2551 10 10 10:10:10", "y", "2550-2551",
+
+ "th", "2550 10 10 10:10:10", "2551 10 10 10:10:10", "M", "10/50 \\u2013 10/51",
+
+
+ "th", "2550 10 10 10:10:10", "2550 11 10 10:10:10", "EEEEdMMMy", "\\u0E27\\u0E31\\u0E19\\u0E1E\\u0E38\\u0E18 10 \\u0E15.\\u0E04. \\u2013 \\u0E27\\u0E31\\u0E19\\u0E40\\u0E2A\\u0E32\\u0E23\\u0E4C 10 \\u0E1E.\\u0E22. 2550",
+
+
+ "th", "2550 10 10 10:10:10", "2550 11 10 10:10:10", "dMMM", "10 \\u0E15.\\u0E04. \\u2013 10 \\u0E1E.\\u0E22.",
+
+ "th", "2550 10 10 10:10:10", "2550 11 10 10:10:10", "MMMy", "\\u0E15.\\u0E04.-\\u0E1E.\\u0E22. 2550",
+
+ "th", "2550 10 10 10:10:10", "2550 11 10 10:10:10", "dM", "10/10 - 10/11",
+
+ "th", "2550 10 10 10:10:10", "2550 11 10 10:10:10", "My", "10/50 \\u2013 11/50",
+
+
+ "th", "2550 10 10 10:10:10", "2550 11 10 10:10:10", "d", "10/10 - 10/11",
+
+ "th", "2550 10 10 10:10:10", "2550 11 10 10:10:10", "y", "2550",
+
+
+ "th", "2550 10 10 10:10:10", "2550 11 10 10:10:10", "MMM", "\\u0E15.\\u0E04.-\\u0E1E.\\u0E22.",
+
};
expect(DATA, DATA.length);
}
diff --git a/readme.html b/readme.html
index e81e945..52eae22 100644
--- a/readme.html
+++ b/readme.html
@@ -184,6 +184,7 @@
<li><a href="http://bugs.icu-project.org/trac/ticket/7395">#7395</a> gatherapi tool doesn't handle 'synthetic' methods</li>
<li><a href="http://bugs.icu-project.org/trac/ticket/7594">#7594</a> Serialization CoverageTest is broken in ICU 4.4</li>
<li><a href="http://bugs.icu-project.org/trac/ticket/7595">#7595</a> SimpleDateFormat fails to handle very long field patterns</li>
+<li><a href="http://bugs.icu-project.org/trac/ticket/7644">#7644</a> Enable non-Gregorian calendars for DateIntervalFormat</li>
</ul>
<h3 class="doc"><a name="license"></a>License Information</h3>