am dbca824d: Merge "Add DateFormat.getBestDateTimePattern." into jb-mr2-dev
* commit 'dbca824dc00209c603a956f45bb684e57ee3e478': Add DateFormat.getBestDateTimePattern.
This commit is contained in:
@@ -22805,6 +22805,7 @@ package android.text.format {
|
||||
method public static java.lang.CharSequence format(java.lang.CharSequence, long);
|
||||
method public static java.lang.CharSequence format(java.lang.CharSequence, java.util.Date);
|
||||
method public static java.lang.CharSequence format(java.lang.CharSequence, java.util.Calendar);
|
||||
method public static java.lang.String getBestDateTimePattern(java.util.Locale, java.lang.String);
|
||||
method public static java.text.DateFormat getDateFormat(android.content.Context);
|
||||
method public static char[] getDateFormatOrder(android.content.Context);
|
||||
method public static java.text.DateFormat getLongDateFormat(android.content.Context);
|
||||
|
||||
@@ -31,6 +31,7 @@ import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
import libcore.icu.ICU;
|
||||
import libcore.icu.LocaleData;
|
||||
|
||||
/**
|
||||
@@ -43,6 +44,9 @@ import libcore.icu.LocaleData;
|
||||
* for both formatting and parsing dates. For the canonical documentation
|
||||
* of format strings, see {@link java.text.SimpleDateFormat}.
|
||||
*
|
||||
* <p>In cases where the system does not provide a suitable pattern,
|
||||
* this class offers the {@link #getBestDateTimePattern} method.
|
||||
*
|
||||
* <p>The {@code format} methods in this class implement a subset of Unicode
|
||||
* <a href="http://www.unicode.org/reports/tr35/#Date_Format_Patterns">UTS #35</a> patterns.
|
||||
* The subset currently supported by this class includes the following format characters:
|
||||
@@ -163,6 +167,37 @@ public class DateFormat {
|
||||
return value.equals("24");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the best possible localized form of the given skeleton for the given
|
||||
* locale. A skeleton is similar to, and uses the same format characters as, a Unicode
|
||||
* <a href="http://www.unicode.org/reports/tr35/#Date_Format_Patterns">UTS #35</a>
|
||||
* pattern.
|
||||
*
|
||||
* <p>One difference is that order is irrelevant. For example, "MMMMd" will return
|
||||
* "MMMM d" in the {@code en_US} locale, but "d. MMMM" in the {@code de_CH} locale.
|
||||
*
|
||||
* <p>Note also in that second example that the necessary punctuation for German was
|
||||
* added. For the same input in {@code es_ES}, we'd have even more extra text:
|
||||
* "d 'de' MMMM".
|
||||
*
|
||||
* <p>This method will automatically correct for grammatical necessity. Given the
|
||||
* same "MMMMd" input, this method will return "d LLLL" in the {@code fa_IR} locale,
|
||||
* where stand-alone months are necessary. Lengths are preserved where meaningful,
|
||||
* so "Md" would give a different result to "MMMd", say, except in a locale such as
|
||||
* {@code ja_JP} where there is only one length of month.
|
||||
*
|
||||
* <p>This method will only return patterns that are in CLDR, and is useful whenever
|
||||
* you know what elements you want in your format string but don't want to make your
|
||||
* code specific to any one locale.
|
||||
*
|
||||
* @param locale the locale into which the skeleton should be localized
|
||||
* @param skeleton a skeleton as described above
|
||||
* @return a string pattern suitable for use with {@link java.text.SimpleDateFormat}.
|
||||
*/
|
||||
public static String getBestDateTimePattern(Locale locale, String skeleton) {
|
||||
return ICU.getBestDateTimePattern(skeleton, locale.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a {@link java.text.DateFormat} object that can format the time according
|
||||
* to the current locale and the user's 12-/24-hour clock preference.
|
||||
|
||||
Reference in New Issue
Block a user