summaryrefslogtreecommitdiffstats
path: root/core/java/android/text/format
diff options
context:
space:
mode:
authorNarayan Kamath <narayan@google.com>2014-11-18 13:23:02 +0000
committerNarayan Kamath <narayan@google.com>2014-11-24 16:05:19 +0000
commitf91f06a5991451e4af3cf99eba791cb3009810d2 (patch)
treeaf96187cb72fd6cfa761ff5d77fe567b5b2a0f11 /core/java/android/text/format
parentff4dd15cd024f72cbd2b6d547356de030b2dd71c (diff)
downloadframeworks_base-f91f06a5991451e4af3cf99eba791cb3009810d2.zip
frameworks_base-f91f06a5991451e4af3cf99eba791cb3009810d2.tar.gz
frameworks_base-f91f06a5991451e4af3cf99eba791cb3009810d2.tar.bz2
Stop reading Settings.System.DATE_FORMAT.
Also, move over DateFormat.getInstance(SHORT) instead of LocaleData.shortDateFormat4 (which forces 4 digit years). Based on an analysis of git history, there seems to be no real motiviation for using 4 digit years. If anyone in the platform complains loudly, we could look at using a skeleton pattern instead of just replacing 'y' with 'yy'. If third party apps are affected, we could add a targetSdkversion based check and revert to the old behaviour for older targetSdks. bug: 18388178 bug: 18322220 Change-Id: Ieab2b41691958a2e668d382c5a6b3d9aaf741ed2
Diffstat (limited to 'core/java/android/text/format')
-rwxr-xr-xcore/java/android/text/format/DateFormat.java73
1 files changed, 10 insertions, 63 deletions
diff --git a/core/java/android/text/format/DateFormat.java b/core/java/android/text/format/DateFormat.java
index d48f551..d515e21 100755
--- a/core/java/android/text/format/DateFormat.java
+++ b/core/java/android/text/format/DateFormat.java
@@ -221,68 +221,13 @@ public class DateFormat {
/**
* Returns a {@link java.text.DateFormat} object that can format the date
- * in short form (such as 12/31/1999) according
- * to the current locale and the user's date-order preference.
+ * in short form according to the current locale.
+ *
* @param context the application context
* @return the {@link java.text.DateFormat} object that properly formats the date.
*/
public static java.text.DateFormat getDateFormat(Context context) {
- String value = Settings.System.getString(context.getContentResolver(),
- Settings.System.DATE_FORMAT);
-
- return getDateFormatForSetting(context, value);
- }
-
- /**
- * Returns a {@link java.text.DateFormat} object to format the date
- * as if the date format setting were set to <code>value</code>,
- * including null to use the locale's default format.
- * @param context the application context
- * @param value the date format setting string to interpret for
- * the current locale
- * @hide
- */
- public static java.text.DateFormat getDateFormatForSetting(Context context,
- String value) {
- String format = getDateFormatStringForSetting(context, value);
- return new java.text.SimpleDateFormat(format);
- }
-
- private static String getDateFormatStringForSetting(Context context, String value) {
- if (value != null) {
- int month = value.indexOf('M');
- int day = value.indexOf('d');
- int year = value.indexOf('y');
-
- if (month >= 0 && day >= 0 && year >= 0) {
- String template = context.getString(R.string.numeric_date_template);
- if (year < month && year < day) {
- if (month < day) {
- value = String.format(template, "yyyy", "MM", "dd");
- } else {
- value = String.format(template, "yyyy", "dd", "MM");
- }
- } else if (month < day) {
- if (day < year) {
- value = String.format(template, "MM", "dd", "yyyy");
- } else { // unlikely
- value = String.format(template, "MM", "yyyy", "dd");
- }
- } else { // day < month
- if (month < year) {
- value = String.format(template, "dd", "MM", "yyyy");
- } else { // unlikely
- value = String.format(template, "dd", "yyyy", "MM");
- }
- }
-
- return value;
- }
- }
-
- // The setting is not set; use the locale's default.
- LocaleData d = LocaleData.get(context.getResources().getConfiguration().locale);
- return d.shortDateFormat4;
+ return java.text.DateFormat.getDateInstance(java.text.DateFormat.SHORT);
}
/**
@@ -315,14 +260,16 @@ public class DateFormat {
* order returned here.
*/
public static char[] getDateFormatOrder(Context context) {
- return ICU.getDateFormatOrder(getDateFormatString(context));
+ return ICU.getDateFormatOrder(getDateFormatString());
}
- private static String getDateFormatString(Context context) {
- String value = Settings.System.getString(context.getContentResolver(),
- Settings.System.DATE_FORMAT);
+ private static String getDateFormatString() {
+ java.text.DateFormat df = java.text.DateFormat.getDateInstance(java.text.DateFormat.SHORT);
+ if (df instanceof SimpleDateFormat) {
+ return ((SimpleDateFormat) df).toPattern();
+ }
- return getDateFormatStringForSetting(context, value);
+ throw new AssertionError("!(df instanceof SimpleDateFormat)");
}
/**