summaryrefslogtreecommitdiffstats
path: root/core/java/android/text
diff options
context:
space:
mode:
authorAndroid (Google) Code Review <android-gerrit@google.com>2009-07-24 16:08:45 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2009-07-24 16:08:45 -0700
commit41220f2c5b674e317a9edd526bcfca6c542c1a15 (patch)
treeba90c8199ccc948a01fd0e29fef9e51ad684e798 /core/java/android/text
parent27700ef16b9058a3cfa4010a18d843888ef4b07d (diff)
parent7c187de14f6b5ec6d90bc8e26265a2ca2824e39a (diff)
downloadframeworks_base-41220f2c5b674e317a9edd526bcfca6c542c1a15.zip
frameworks_base-41220f2c5b674e317a9edd526bcfca6c542c1a15.tar.gz
frameworks_base-41220f2c5b674e317a9edd526bcfca6c542c1a15.tar.bz2
am 7c187de1: Merge change 8462 into donut
Merge commit '7c187de14f6b5ec6d90bc8e26265a2ca2824e39a' * commit '7c187de14f6b5ec6d90bc8e26265a2ca2824e39a': Make the DatePicker respect the date format setting if the date is numeric.
Diffstat (limited to 'core/java/android/text')
-rw-r--r--core/java/android/text/format/DateFormat.java34
1 files changed, 16 insertions, 18 deletions
diff --git a/core/java/android/text/format/DateFormat.java b/core/java/android/text/format/DateFormat.java
index 3d10f17..524f941 100644
--- a/core/java/android/text/format/DateFormat.java
+++ b/core/java/android/text/format/DateFormat.java
@@ -284,6 +284,12 @@ public class DateFormat {
*/
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');
@@ -291,7 +297,7 @@ public class DateFormat {
if (month >= 0 && day >= 0 && year >= 0) {
String template = context.getString(R.string.numeric_date_template);
- if (year < month) {
+ if (year < month && year < day) {
if (month < day) {
value = String.format(template, "yyyy", "MM", "dd");
} else {
@@ -311,7 +317,7 @@ public class DateFormat {
}
}
- return new java.text.SimpleDateFormat(value);
+ return value;
}
}
@@ -321,7 +327,7 @@ public class DateFormat {
* so that we get a four-digit year instead a two-digit year.
*/
value = context.getString(R.string.numeric_date_format);
- return new java.text.SimpleDateFormat(value);
+ return value;
}
/**
@@ -347,7 +353,11 @@ public class DateFormat {
/**
* Gets the current date format stored as a char array. The array will contain
* 3 elements ({@link #DATE}, {@link #MONTH}, and {@link #YEAR}) in the order
- * preferred by the user.
+ * specified by the user's format preference. Note that this order is
+ * only appropriate for all-numeric dates; spelled-out (MEDIUM and LONG)
+ * dates will generally contain other punctuation, spaces, or words,
+ * not just the day, month, and year, and not necessarily in the same
+ * order returned here.
*/
public static final char[] getDateFormatOrder(Context context) {
char[] order = new char[] {DATE, MONTH, YEAR};
@@ -380,22 +390,10 @@ public class DateFormat {
}
private static String getDateFormatString(Context context) {
- java.text.DateFormat df;
- df = java.text.DateFormat.getDateInstance(java.text.DateFormat.SHORT);
- if (df instanceof SimpleDateFormat) {
- return ((SimpleDateFormat) df).toPattern();
- }
-
String value = Settings.System.getString(context.getContentResolver(),
Settings.System.DATE_FORMAT);
- if (value == null || value.length() < 6) {
- /*
- * No need to localize -- this is an emergency fallback in case
- * the setting is missing, but it should always be set.
- */
- value = "MM-dd-yyyy";
- }
- return value;
+
+ return getDateFormatStringForSetting(context, value);
}
/**