summaryrefslogtreecommitdiff
path: root/icu4j/main/classes
diff options
context:
space:
mode:
authorJoachim Sauer <jsauer@google.com>2017-01-12 16:43:40 +0000
committerandroid-build-merger <android-build-merger@google.com>2017-01-12 16:43:40 +0000
commitde8aa8c36173db1673559a61735f22d96d747177 (patch)
tree55ae21f4db7f7207274c7edd46f09b415af2dae7 /icu4j/main/classes
parent8d38e91fe2d780ae8c0fa94c6d81f6e67cee2add (diff)
parent0ae655e3110acd31ff6dcb1e6975d76e0625f69f (diff)
downloadicu-de8aa8c36173db1673559a61735f22d96d747177.tar.gz
Add/expose APIs needed by java.time. am: 22b47ef9dd
am: 0ae655e311 Change-Id: I8f9df450993677076ed784eb466b003d4e3d3dbd
Diffstat (limited to 'icu4j/main/classes')
-rw-r--r--icu4j/main/classes/core/src/com/ibm/icu/text/DateFormatSymbols.java27
-rw-r--r--icu4j/main/classes/core/src/com/ibm/icu/util/Calendar.java51
2 files changed, 77 insertions, 1 deletions
diff --git a/icu4j/main/classes/core/src/com/ibm/icu/text/DateFormatSymbols.java b/icu4j/main/classes/core/src/com/ibm/icu/text/DateFormatSymbols.java
index f50215335..bc8a23649 100644
--- a/icu4j/main/classes/core/src/com/ibm/icu/text/DateFormatSymbols.java
+++ b/icu4j/main/classes/core/src/com/ibm/icu/text/DateFormatSymbols.java
@@ -755,6 +755,19 @@ public class DateFormatSymbols implements Serializable, Cloneable {
eraNames = duplicate(newEraNames);
}
+ // Android patch (http://b/30464240) start: Add getter for narrow eras.
+ /**
+ * {@icu} Returns narrow era name strings. For example: "A" and "B".
+ * @return the era strings.
+ * @internal
+ * @deprecated This API is ICU internal only.
+ */
+ @Deprecated
+ public String[] getNarrowEras() {
+ return duplicate(narrowEras);
+ }
+ // Android patch end.
+
/**
* Returns month strings. For example: "January", "February", etc.
* @return the month strings.
@@ -2306,6 +2319,20 @@ public class DateFormatSymbols implements Serializable, Cloneable {
initializeData(locale, calType);
}
+ // Android patch (http://b/30464240) start: Add constructor taking a calendar type.
+ /**
+ * Variant of DateFormatSymbols(Calendar, ULocale) that takes the calendar type
+ * instead of a Calendar instance.
+ * @see #DateFormatSymbols(Calendar, Locale)
+ * @internal
+ * @deprecated This API is ICU internal only.
+ */
+ @Deprecated
+ public DateFormatSymbols(ULocale locale, String calType) {
+ initializeData(locale, calType);
+ }
+ // Android patch end.
+
/**
* Fetches a custom calendar's DateFormatSymbols out of the given resource
* bundle. Symbols that are not overridden are inherited from the
diff --git a/icu4j/main/classes/core/src/com/ibm/icu/util/Calendar.java b/icu4j/main/classes/core/src/com/ibm/icu/util/Calendar.java
index ea0aee268..33cf0c6d9 100644
--- a/icu4j/main/classes/core/src/com/ibm/icu/util/Calendar.java
+++ b/icu4j/main/classes/core/src/com/ibm/icu/util/Calendar.java
@@ -3587,6 +3587,51 @@ public abstract class Calendar implements Serializable, Cloneable, Comparable<Ca
return result;
}
+ // Android patch (http://b/28832222) start.
+ // Expose method to get format string for java.time.
+ /**
+ * Get the date time format string for the specified values.
+ * This is a copy of {@link #formatHelper(Calendar, ULocale, int, int)} with the following
+ * changes:
+ * <ul>
+ * <li>Made public, but hidden</li>
+ * <li>take calendar type string instead of Calendar</li>
+ * <li>Ignore overrides</li>
+ * <li>Return format string instead of DateFormat.</li>
+ * </ul>
+ * This is not meant as public API.
+ * @internal
+ */
+ // TODO: Check if calType can be passed via keyword on loc parameter instead.
+ public static String getDateTimeFormatString(ULocale loc, String calType, int dateStyle,
+ int timeStyle) {
+ if (timeStyle < DateFormat.NONE || timeStyle > DateFormat.SHORT) {
+ throw new IllegalArgumentException("Illegal time style " + timeStyle);
+ }
+ if (dateStyle < DateFormat.NONE || dateStyle > DateFormat.SHORT) {
+ throw new IllegalArgumentException("Illegal date style " + dateStyle);
+ }
+
+ PatternData patternData = PatternData.make(loc, calType);
+
+ // Resolve a pattern for the date/time style
+ String pattern = null;
+ if ((timeStyle >= 0) && (dateStyle >= 0)) {
+ pattern = SimpleFormatterImpl.formatRawPattern(
+ patternData.getDateTimePattern(dateStyle), 2, 2,
+ patternData.patterns[timeStyle],
+ patternData.patterns[dateStyle + 4]);
+ } else if (timeStyle >= 0) {
+ pattern = patternData.patterns[timeStyle];
+ } else if (dateStyle >= 0) {
+ pattern = patternData.patterns[dateStyle + 4];
+ } else {
+ throw new IllegalArgumentException("No date or time style specified");
+ }
+ return pattern;
+ }
+ // Android patch (http://b/28832222) end.
+
static class PatternData {
// TODO make this even more object oriented
private String[] patterns;
@@ -3604,8 +3649,12 @@ public abstract class Calendar implements Serializable, Cloneable, Comparable<Ca
return dateTimePattern;
}
private static PatternData make(Calendar cal, ULocale loc) {
+ // Android patch (http://b/28832222) start.
+ return make(loc, cal.getType());
+ }
+ private static PatternData make(ULocale loc, String calType) {
+ // Android patch (http://b/28832222) end.
// First, try to get a pattern from PATTERN_CACHE
- String calType = cal.getType();
String key = loc.getBaseName() + "+" + calType;
PatternData patternData = PATTERN_CACHE.get(key);
if (patternData == null) {