From 99b78b3eebd4fa75c3d8a4a4e500a91faf5a4c12 Mon Sep 17 00:00:00 2001 From: "Philip P. Moltmann" Date: Mon, 26 Oct 2015 17:30:10 -0700 Subject: [PATCH] Deal with daylight savings time in battery chart. Without daylight saving time the middle between two beginnings of days can only be another beginning of a day or noon. Due to daylight savings time this can be shifted by up to one hour in either direction. This change corrects the middle value. Testing Done: Tried the calculation of the three values with Lisbon time and mStartWallTime = 1414254027000L; mEndWallTime = 1414473627000L; which spans over 10/26/2014, the day daylight saving ended in Lisbon. Change-Id: I2d2ba6e1fd2e409ca3f6b0f7674ec250da7ffad5 --- .../android/settings/fuelgauge/BatteryHistoryChart.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/com/android/settings/fuelgauge/BatteryHistoryChart.java b/src/com/android/settings/fuelgauge/BatteryHistoryChart.java index 5c53fd12bad..cd6c62f9a52 100644 --- a/src/com/android/settings/fuelgauge/BatteryHistoryChart.java +++ b/src/com/android/settings/fuelgauge/BatteryHistoryChart.java @@ -1118,8 +1118,13 @@ public class BatteryHistoryChart extends View { if (startRoundTime < endRoundTime) { addDateLabel(calStart, mLevelLeft, mLevelRight, isDayFirst); Calendar calMid = Calendar.getInstance(); - calMid.setTimeInMillis(startRoundTime + ((endRoundTime - startRoundTime) / 2)); + + // The middle between two beginnings of days can be anywhere between -1 to 13 + // after the beginning of the "median" day. + calMid.setTimeInMillis(startRoundTime + ((endRoundTime - startRoundTime) / 2) + + 2 * 60 * 60 * 1000); calMid.set(Calendar.HOUR_OF_DAY, 0); + calMid.set(Calendar.MINUTE, 0); long calMidMillis = calMid.getTimeInMillis(); if (calMidMillis > startRoundTime && calMidMillis < endRoundTime) { addDateLabel(calMid, mLevelLeft, mLevelRight, isDayFirst);