Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1d663e72 authored by Lucas Dupin's avatar Lucas Dupin Committed by Automerger Merge Worker
Browse files

Merge "Time for dark theme doesnt format 24 hr correctly" into rvc-d1-dev am:...

Merge "Time for dark theme doesnt format 24 hr correctly" into rvc-d1-dev am: e899f749 am: 5f44b7cf am: 6430a4b8

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/12337522

Change-Id: Iac01c66216d6ab98654b97f33505d9f60714c78e
parents 6af03420 6430a4b8
Loading
Loading
Loading
Loading
+12 −9
Original line number Diff line number Diff line
@@ -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() {