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
This commit is contained in:
Philip P. Moltmann
2015-10-26 17:30:10 -07:00
parent 61eaed7bfb
commit 99b78b3eeb

View File

@@ -1118,8 +1118,13 @@ public class BatteryHistoryChart extends View {
if (startRoundTime < endRoundTime) { if (startRoundTime < endRoundTime) {
addDateLabel(calStart, mLevelLeft, mLevelRight, isDayFirst); addDateLabel(calStart, mLevelLeft, mLevelRight, isDayFirst);
Calendar calMid = Calendar.getInstance(); 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.HOUR_OF_DAY, 0);
calMid.set(Calendar.MINUTE, 0);
long calMidMillis = calMid.getTimeInMillis(); long calMidMillis = calMid.getTimeInMillis();
if (calMidMillis > startRoundTime && calMidMillis < endRoundTime) { if (calMidMillis > startRoundTime && calMidMillis < endRoundTime) {
addDateLabel(calMid, mLevelLeft, mLevelRight, isDayFirst); addDateLabel(calMid, mLevelLeft, mLevelRight, isDayFirst);