From cdabed7692f1ed33e5bb9f41a0f80400da0dfd0f Mon Sep 17 00:00:00 2001 From: Travis Keep Date: Fri, 5 Sep 2014 22:15:50 +0000 Subject: [PATCH] ICU-9509 Add DateFormat.getInstanceForSkeleton methods. X-SVN-Rev: 36369 --- .../core/src/com/ibm/icu/text/DateFormat.java | 113 ++++++++++++++++-- 1 file changed, 102 insertions(+), 11 deletions(-) diff --git a/icu4j/main/classes/core/src/com/ibm/icu/text/DateFormat.java b/icu4j/main/classes/core/src/com/ibm/icu/text/DateFormat.java index f3e9dd5b0fc..0e61bdfe210 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/text/DateFormat.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/text/DateFormat.java @@ -1971,7 +1971,7 @@ public abstract class DateFormat extends UFormat { static final public DateFormat getDateTimeInstance(Calendar cal, int dateStyle, int timeStyle) { return getDateTimeInstance(cal, dateStyle, timeStyle, ULocale.getDefault(Category.FORMAT)); } - + /** * {@icu} Returns a {@link DateFormat} object that can be used to format dates and times in * the default locale. @@ -1980,9 +1980,9 @@ public abstract class DateFormat extends UFormat { * {@link DateTimePatternGenerator}.) This can be {@link DateFormat#ABBR_MONTH}, * {@link DateFormat#MONTH_WEEKDAY_DAY}, etc. * - * @stable ICU 4.0 + * @draft ICU 54 */ - public final static DateFormat getPatternInstance(String skeleton) { + public final static DateFormat getInstanceForSkeleton(String skeleton) { return getPatternInstance(skeleton, ULocale.getDefault(Category.FORMAT)); } @@ -1996,9 +1996,9 @@ public abstract class DateFormat extends UFormat { * * @param locale The locale for which the date/time format is desired. * - * @stable ICU 4.0 + * @draft ICU 54 */ - public final static DateFormat getPatternInstance(String skeleton, Locale locale) { + public final static DateFormat getInstanceForSkeleton(String skeleton, Locale locale) { return getPatternInstance(skeleton, ULocale.forLocale(locale)); } @@ -2012,9 +2012,9 @@ public abstract class DateFormat extends UFormat { * * @param locale The locale for which the date/time format is desired. * - * @stable ICU 4.0 + * @draft ICU 54 */ - public final static DateFormat getPatternInstance(String skeleton, ULocale locale) { + public final static DateFormat getInstanceForSkeleton(String skeleton, ULocale locale) { DateTimePatternGenerator generator = DateTimePatternGenerator.getInstance(locale); final String bestPattern = generator.getBestPattern(skeleton); return new SimpleDateFormat(bestPattern, locale); @@ -2033,9 +2033,9 @@ public abstract class DateFormat extends UFormat { * * @param locale The locale for which the date/time format is desired. * - * @stable ICU 4.0 + * @draft ICU 54 */ - public final static DateFormat getPatternInstance(Calendar cal, String skeleton, Locale locale) { + public final static DateFormat getInstanceForSkeleton(Calendar cal, String skeleton, Locale locale) { return getPatternInstance(cal, skeleton, ULocale.forLocale(locale)); } @@ -2052,9 +2052,9 @@ public abstract class DateFormat extends UFormat { * * @param locale The locale for which the date/time format is desired. * - * @stable ICU 4.0 + * @draft ICU 54 */ - public final static DateFormat getPatternInstance( + public final static DateFormat getInstanceForSkeleton( Calendar cal, String skeleton, ULocale locale) { DateTimePatternGenerator generator = DateTimePatternGenerator.getInstance(locale); final String bestPattern = generator.getBestPattern(skeleton); @@ -2063,6 +2063,97 @@ public abstract class DateFormat extends UFormat { return format; } + + /** + * {@icu} Returns a {@link DateFormat} object that can be used to format dates and times in + * the default locale. + * The getInstanceForSkeleton methods are preferred over the getPatternInstance methods. + * + * @param skeleton The skeleton that selects the fields to be formatted. (Uses the + * {@link DateTimePatternGenerator}.) This can be {@link DateFormat#ABBR_MONTH}, + * {@link DateFormat#MONTH_WEEKDAY_DAY}, etc. + * + * @stable ICU 4.0 + */ + public final static DateFormat getPatternInstance(String skeleton) { + return getInstanceForSkeleton(skeleton); + } + + /** + * {@icu} Returns a {@link DateFormat} object that can be used to format dates and times in + * the given locale. + * The getInstanceForSkeleton methods are preferred over the getPatternInstance methods. + * + * @param skeleton The skeleton that selects the fields to be formatted. (Uses the + * {@link DateTimePatternGenerator}.) This can be {@link DateFormat#ABBR_MONTH}, + * {@link DateFormat#MONTH_WEEKDAY_DAY}, etc. + * + * @param locale The locale for which the date/time format is desired. + * + * @stable ICU 4.0 + */ + public final static DateFormat getPatternInstance(String skeleton, Locale locale) { + return getInstanceForSkeleton(skeleton, locale); + } + + /** + * {@icu} Returns a {@link DateFormat} object that can be used to format dates and times in + * the given locale. + * The getInstanceForSkeleton methods are preferred over the getPatternInstance methods. + * + * @param skeleton The skeleton that selects the fields to be formatted. (Uses the + * {@link DateTimePatternGenerator}.) This can be {@link DateFormat#ABBR_MONTH}, + * {@link DateFormat#MONTH_WEEKDAY_DAY}, etc. + * + * @param locale The locale for which the date/time format is desired. + * + * @stable ICU 4.0 + */ + public final static DateFormat getPatternInstance(String skeleton, ULocale locale) { + return getInstanceForSkeleton(skeleton, locale); + } + + /** + * {@icu} Creates a {@link DateFormat} object that can be used to format dates and + * times in the calendar system specified by cal. + * The getInstanceForSkeleton methods are preferred over the getPatternInstance methods. + * + * @param cal The calendar system for which a date/time format is desired. + * + * @param skeleton The skeleton that selects the fields to be formatted. (Uses the + * {@link DateTimePatternGenerator}.) This can be + * {@link DateFormat#ABBR_MONTH}, {@link DateFormat#MONTH_WEEKDAY_DAY}, + * etc. + * + * @param locale The locale for which the date/time format is desired. + * + * @stable ICU 4.0 + */ + public final static DateFormat getPatternInstance(Calendar cal, String skeleton, Locale locale) { + return getInstanceForSkeleton(cal, skeleton, locale); + } + + /** + * {@icu} Creates a {@link DateFormat} object that can be used to format dates and + * times in the calendar system specified by cal. + * The getInstanceForSkeleton methods are preferred over the getPatternInstance methods. + * + * @param cal The calendar system for which a date/time format is desired. + * + * @param skeleton The skeleton that selects the fields to be formatted. (Uses the + * {@link DateTimePatternGenerator}.) This can be + * {@link DateFormat#ABBR_MONTH}, {@link DateFormat#MONTH_WEEKDAY_DAY}, + * etc. + * + * @param locale The locale for which the date/time format is desired. + * + * @stable ICU 4.0 + */ + public final static DateFormat getPatternInstance( + Calendar cal, String skeleton, ULocale locale) { + return getInstanceForSkeleton(cal, skeleton, locale); + } + /** * The instances of this inner class are used as attribute keys and values * in AttributedCharacterIterator that -- 2.40.0