summaryrefslogtreecommitdiff
path: root/core/java/android
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2013-08-16 11:56:35 -0700
committerElliott Hughes <enh@google.com>2013-08-16 14:53:26 -0700
commitf9818d33f94686ee9c80697ec79ef557a7b77176 (patch)
tree42b6f0b33413866ba7fc29b820ed3af039e81093 /core/java/android
parent3c226bf6acea0b8dff34a2113009b6d918a3af65 (diff)
Fix NPE in DateFormat.is24HourFormat.
In some cases, we end up being called by code that doesn't have a valid Context. It got away with this historically because it wasn't formatting times (just dates), so it never went down a path that tried to query the user's 12/24-hour preference. This patch just ensures that we don't try to get the preference unless we actually need it. Bug: 10339015 (cherry picked from commit 8d8ef00c8276200f108433922761401817fd9a50) Change-Id: If074a67fa52943c0ec7bb5c5bbe5a11f54fb1f97
Diffstat (limited to 'core/java/android')
-rw-r--r--core/java/android/text/format/DateUtils.java5
1 files changed, 3 insertions, 2 deletions
diff --git a/core/java/android/text/format/DateUtils.java b/core/java/android/text/format/DateUtils.java
index 2b805a9bc367..22675b4af479 100644
--- a/core/java/android/text/format/DateUtils.java
+++ b/core/java/android/text/format/DateUtils.java
@@ -816,9 +816,10 @@ public class DateUtils
*/
public static Formatter formatDateRange(Context context, Formatter formatter, long startMillis,
long endMillis, int flags, String timeZone) {
- // icu4c will fall back to the locale's preferred 12/24 format,
+ // If we're being asked to format a time without being explicitly told whether to use
+ // the 12- or 24-hour clock, icu4c will fall back to the locale's preferred 12/24 format,
// but we want to fall back to the user's preference.
- if ((flags & (FORMAT_12HOUR | FORMAT_24HOUR)) == 0) {
+ if ((flags & (FORMAT_SHOW_TIME | FORMAT_12HOUR | FORMAT_24HOUR)) == FORMAT_SHOW_TIME) {
flags |= DateFormat.is24HourFormat(context) ? FORMAT_24HOUR : FORMAT_12HOUR;
}