Align system time 12-24 hour format in the time slot information
align the time format configuration in the Settings -> System -> Date/Time to show 12- or 24- hour format in the usage time slot screenshot: https://screenshot.googleplex.com/3w2SFvBLpC5oHBs screenshot: https://screenshot.googleplex.com/86uCq6R4PKEg9RD screenshot: https://screenshot.googleplex.com/3easrEFMQdZEjGP screenshot: https://screenshot.googleplex.com/7dPWVJNTbSShFPa Bug: 187783891 Test: make SettingsRoboTests Change-Id: I9af0a69bd7c67562526bd5ee74a657635068ef44
This commit is contained in:
@@ -71,6 +71,7 @@ public final class ConvertUtils {
|
||||
|
||||
private static String sZoneId;
|
||||
private static String sZoneIdForHour;
|
||||
private static boolean sIs24HourFormat;
|
||||
|
||||
@VisibleForTesting
|
||||
static SimpleDateFormat sSimpleDateFormat;
|
||||
@@ -134,11 +135,15 @@ public final class ConvertUtils {
|
||||
}
|
||||
|
||||
/** Converts UTC timestamp to local time hour data. */
|
||||
public static String utcToLocalTimeHour(long timestamp) {
|
||||
public static String utcToLocalTimeHour(long timestamp, boolean is24HourFormat) {
|
||||
final String currentZoneId = TimeZone.getDefault().getID();
|
||||
if (!currentZoneId.equals(sZoneIdForHour) || sSimpleDateFormatForHour == null) {
|
||||
if (!currentZoneId.equals(sZoneIdForHour)
|
||||
|| sIs24HourFormat != is24HourFormat
|
||||
|| sSimpleDateFormatForHour == null) {
|
||||
sZoneIdForHour = currentZoneId;
|
||||
sSimpleDateFormatForHour = new SimpleDateFormat("h aa", Locale.ENGLISH);
|
||||
sIs24HourFormat = is24HourFormat;
|
||||
sSimpleDateFormatForHour = new SimpleDateFormat(
|
||||
sIs24HourFormat ? "HH" : "h aa", Locale.ENGLISH);
|
||||
}
|
||||
return sSimpleDateFormatForHour.format(new Date(timestamp))
|
||||
.toLowerCase(Locale.getDefault());
|
||||
|
Reference in New Issue
Block a user