health: Format notification's target time according to locale
Fixes: 8a7af5a974
Fixes: https://gitlab.com/LineageOS/issues/android/-/issues/8317
Change-Id: I2c059da77c54c4fea11bdbabd1dde752f74ca6cf
This commit is contained in:
@@ -319,7 +319,7 @@ public class ChargingControlController extends LineageHealthFeature {
|
||||
private ChargeTime getChargeTime() {
|
||||
// Get duration to target full time
|
||||
final long currentTime = System.currentTimeMillis();
|
||||
Log.i(TAG, "Current time is " + msToString(currentTime));
|
||||
Log.i(TAG, "Current time is " + msToString(mContext, currentTime));
|
||||
long targetTime = 0, startTime = currentTime;
|
||||
int mode = getMode();
|
||||
|
||||
@@ -362,8 +362,9 @@ public class ChargingControlController extends LineageHealthFeature {
|
||||
return null;
|
||||
}
|
||||
|
||||
Log.i(TAG, "Got target time " + msToString(targetTime) + ", start time " +
|
||||
msToString(startTime) + ", current time " + msToString(currentTime));
|
||||
Log.i(TAG, "Got target time " + msToString(mContext, targetTime)
|
||||
+ ", start time " + msToString(mContext, startTime)
|
||||
+ ", current time " + msToString(mContext, currentTime));
|
||||
Log.i(TAG, "Raw: " + targetTime + ", " + startTime + ", " + currentTime);
|
||||
|
||||
return new ChargeTime(startTime, targetTime);
|
||||
|
||||
@@ -111,7 +111,7 @@ public class ChargingControlNotification {
|
||||
if (targetTime != null) {
|
||||
message = String.format(
|
||||
mContext.getString(R.string.charging_control_notification_content_target),
|
||||
msToString(targetTime));
|
||||
msToString(mContext, targetTime));
|
||||
} else {
|
||||
message = String.format(
|
||||
mContext.getString(R.string.charging_control_notification_content_limit),
|
||||
|
||||
@@ -5,33 +5,33 @@
|
||||
|
||||
package org.lineageos.platform.internal.health;
|
||||
|
||||
import static java.time.format.FormatStyle.SHORT;
|
||||
import android.content.Context;
|
||||
import android.text.format.DateFormat;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Calendar;
|
||||
import java.util.TimeZone;
|
||||
|
||||
public class Util {
|
||||
private static final DateTimeFormatter mFormatter = DateTimeFormatter.ofLocalizedTime(SHORT);
|
||||
|
||||
/**
|
||||
* Convert milliseconds to a string in the format "hh:mm:ss a".
|
||||
* Convert milliseconds to a string in the current locale's format.
|
||||
*
|
||||
* @param ms milliseconds from epoch
|
||||
* @return formatted time string in current time zone
|
||||
*/
|
||||
static public String msToString(long ms) {
|
||||
final SimpleDateFormat dateFormat = new SimpleDateFormat("hh:mm:ss a");
|
||||
static public String msToString(Context context, long ms) {
|
||||
return DateFormat.getTimeFormat(context).format(msToLocalTime(ms).getTime());
|
||||
}
|
||||
|
||||
static private Calendar msToLocalTime(long ms) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTimeInMillis(ms);
|
||||
return dateFormat.format(calendar.getTime());
|
||||
return calendar;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -243,7 +243,7 @@ public class Toggle extends ChargingControlProvider {
|
||||
public void dump(PrintWriter pw) {
|
||||
pw.println("Provider: " + getClass().getName());
|
||||
pw.println(" mIsLimitSet: " + mIsLimitSet);
|
||||
pw.println(" mSavedTargetTime: " + msToString(mSavedTargetTime));
|
||||
pw.println(" mSavedTargetTime: " + msToString(mContext, mSavedTargetTime));
|
||||
pw.println(" mEstimatedFullTime: " + msToUTCString(mEstimatedFullTime));
|
||||
pw.println(" mStage: " + mStage);
|
||||
pw.println(" mChargeLimitMargin: " + mChargingLimitMargin);
|
||||
|
||||
Reference in New Issue
Block a user