Merge "Time for dark theme doesnt format 24 hr correctly" into rvc-d1-dev
This commit is contained in:
@@ -18,26 +18,29 @@ package com.android.settings.display.darkmode;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import java.time.LocalTime;
|
import java.time.LocalTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.util.Calendar;
|
||||||
import java.util.Locale;
|
import java.util.TimeZone;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Formats LocalTime to the locale time string format
|
* Formats LocalTime to the locale time string format
|
||||||
*/
|
*/
|
||||||
public class TimeFormatter {
|
public class TimeFormatter {
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
private final DateTimeFormatter mFormatter;
|
private final java.text.DateFormat mFormatter;
|
||||||
public TimeFormatter(Context context) {
|
public TimeFormatter(Context context) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
Locale locale = mContext.getResources().getConfiguration().locale;
|
mFormatter = android.text.format.DateFormat.getTimeFormat(context);
|
||||||
if (locale == null) {
|
mFormatter.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||||
locale = Locale.getDefault();
|
|
||||||
}
|
|
||||||
mFormatter = DateTimeFormatter.ofPattern("hh:mm a", locale);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String of(LocalTime time) {
|
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() {
|
public boolean is24HourFormat() {
|
||||||
|
Reference in New Issue
Block a user