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 8d8ef00c82)
Change-Id: If074a67fa52943c0ec7bb5c5bbe5a11f54fb1f97
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user