From b569dfdac8250bc003ddbdc26097768864050810 Mon Sep 17 00:00:00 2001 From: Jay Aliomer Date: Fri, 7 Aug 2020 19:29:31 -0400 Subject: [PATCH] Time for dark theme doesnt format 24 hr correctly Fixes: 163048376 Test: Manual Change-Id: Ia6c2633408670656c2b42bfb724aaf900561682e --- .../display/darkmode/TimeFormatter.java | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/com/android/settings/display/darkmode/TimeFormatter.java b/src/com/android/settings/display/darkmode/TimeFormatter.java index 1032fe1be01..32ff026b7e3 100644 --- a/src/com/android/settings/display/darkmode/TimeFormatter.java +++ b/src/com/android/settings/display/darkmode/TimeFormatter.java @@ -18,26 +18,29 @@ package com.android.settings.display.darkmode; import android.content.Context; import java.time.LocalTime; -import java.time.format.DateTimeFormatter; -import java.util.Locale; +import java.util.Calendar; +import java.util.TimeZone; /** * Formats LocalTime to the locale time string format */ public class TimeFormatter { private final Context mContext; - private final DateTimeFormatter mFormatter; + private final java.text.DateFormat mFormatter; public TimeFormatter(Context context) { mContext = context; - Locale locale = mContext.getResources().getConfiguration().locale; - if (locale == null) { - locale = Locale.getDefault(); - } - mFormatter = DateTimeFormatter.ofPattern("hh:mm a", locale); + mFormatter = android.text.format.DateFormat.getTimeFormat(context); + mFormatter.setTimeZone(TimeZone.getTimeZone("UTC")); } public String of(LocalTime time) { - return mFormatter.format(time); + final Calendar c = Calendar.getInstance(); + c.setTimeZone(mFormatter.getTimeZone()); + c.set(Calendar.HOUR_OF_DAY, time.getHour()); + c.set(Calendar.MINUTE, time.getMinute()); + c.set(Calendar.SECOND, 0); + c.set(Calendar.MILLISECOND, 0); + return mFormatter.format(c.getTime()); } public boolean is24HourFormat() {