Align system time 12-24 hour format in the time slot information
align the time format configuration in the Settings -> System -> Date/Time to show 12- or 24- hour format in the usage time slot screenshot: https://screenshot.googleplex.com/3w2SFvBLpC5oHBs screenshot: https://screenshot.googleplex.com/86uCq6R4PKEg9RD screenshot: https://screenshot.googleplex.com/3easrEFMQdZEjGP screenshot: https://screenshot.googleplex.com/7dPWVJNTbSShFPa Bug: 187783891 Test: make SettingsRoboTests Change-Id: I9af0a69bd7c67562526bd5ee74a657635068ef44
This commit is contained in:
@@ -20,6 +20,7 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.anyLong;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
@@ -604,7 +605,7 @@ public final class BatteryChartPreferenceControllerTest {
|
||||
mBatteryChartPreferenceController.setTimestampLabel();
|
||||
|
||||
verify(mBatteryChartPreferenceController.mBatteryChartView, never())
|
||||
.setTimestamps(any());
|
||||
.setLatestTimestamp(anyLong());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -613,19 +614,11 @@ public final class BatteryChartPreferenceControllerTest {
|
||||
mBatteryChartPreferenceController.mBatteryChartView =
|
||||
spy(new BatteryChartView(mContext));
|
||||
setUpBatteryHistoryKeys();
|
||||
// Generates the expected result.
|
||||
final String[] expectedResults = new String[4];
|
||||
final long timeSlotOffset = DateUtils.HOUR_IN_MILLIS * 8;
|
||||
for (int index = 0; index < expectedResults.length; index++) {
|
||||
expectedResults[index] =
|
||||
ConvertUtils.utcToLocalTimeHour(
|
||||
1619247636826L - (3 - index) * timeSlotOffset);
|
||||
}
|
||||
|
||||
mBatteryChartPreferenceController.setTimestampLabel();
|
||||
|
||||
verify(mBatteryChartPreferenceController.mBatteryChartView)
|
||||
.setTimestamps(expectedResults);
|
||||
.setLatestTimestamp(1619247636826L);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -638,7 +631,7 @@ public final class BatteryChartPreferenceControllerTest {
|
||||
mBatteryChartPreferenceController.setTimestampLabel();
|
||||
|
||||
verify(mBatteryChartPreferenceController.mBatteryChartView)
|
||||
.setTimestamps(any());
|
||||
.setLatestTimestamp(anyLong());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -709,7 +702,7 @@ public final class BatteryChartPreferenceControllerTest {
|
||||
private void setUpBatteryHistoryKeys() {
|
||||
mBatteryChartPreferenceController.mBatteryHistoryKeys =
|
||||
new long[] {1619196786769L, 0L, 1619247636826L};
|
||||
ConvertUtils.utcToLocalTimeHour(/*timestamp=*/ 0);
|
||||
ConvertUtils.utcToLocalTimeHour(/*timestamp=*/ 0, /*is24HourFormat=*/ false);
|
||||
// Simulates the locale in GMT.
|
||||
ConvertUtils.sSimpleDateFormatForHour
|
||||
.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||
|
@@ -41,6 +41,7 @@ import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.ArrayList;
|
||||
import java.util.TimeZone;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public final class BatteryChartViewTest {
|
||||
@@ -227,4 +228,20 @@ public final class BatteryChartViewTest {
|
||||
verify(mBatteryChartView.mHandler)
|
||||
.postDelayed(mBatteryChartView.mUpdateClickableStateRun, 500L);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetLatestTimestamp_generateExpectedTimestamps() {
|
||||
final long timestamp = 1619196786769L;
|
||||
ConvertUtils.sSimpleDateFormatForHour = null;
|
||||
// Invokes the method first to create the SimpleDateFormat.
|
||||
ConvertUtils.utcToLocalTimeHour(/*timestamp=*/ 0, /*is24HourFormat=*/ false);
|
||||
ConvertUtils.sSimpleDateFormatForHour
|
||||
.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles"));
|
||||
final String[] expectedTimestamps =
|
||||
new String[] {"9 am", "5 pm", "1 am", "9 am"};
|
||||
|
||||
mBatteryChartView.setLatestTimestamp(timestamp);
|
||||
|
||||
assertThat(mBatteryChartView.mTimestamps).isEqualTo(expectedTimestamps);
|
||||
}
|
||||
}
|
||||
|
@@ -316,28 +316,41 @@ public final class ConvertUtilsTest {
|
||||
|
||||
@Test
|
||||
public void testUtcToLocalTime_returnExpectedResult() {
|
||||
final long timestamp = 1619196786769L;
|
||||
ConvertUtils.sSimpleDateFormat = null;
|
||||
// Invokes the method first to create the SimpleDateFormat.
|
||||
ConvertUtils.utcToLocalTime(/*timestamp=*/ 0);
|
||||
ConvertUtils.sSimpleDateFormat
|
||||
.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles"));
|
||||
final long timestamp = 1619196786769L;
|
||||
ConvertUtils.sSimpleDateFormat = null;
|
||||
// Invokes the method first to create the SimpleDateFormat.
|
||||
ConvertUtils.utcToLocalTime(/*timestamp=*/ 0);
|
||||
ConvertUtils.sSimpleDateFormat
|
||||
.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles"));
|
||||
|
||||
assertThat(ConvertUtils.utcToLocalTime(timestamp))
|
||||
.isEqualTo("Apr 23,2021 09:53:06");
|
||||
assertThat(ConvertUtils.utcToLocalTime(timestamp))
|
||||
.isEqualTo("Apr 23,2021 09:53:06");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUtcToLocalTmeHour_returnExpectedResult() {
|
||||
final long timestamp = 1619196786769L;
|
||||
ConvertUtils.sSimpleDateFormatForHour = null;
|
||||
// Invokes the method first to create the SimpleDateFormat.
|
||||
ConvertUtils.utcToLocalTimeHour(/*timestamp=*/ 0);
|
||||
ConvertUtils.sSimpleDateFormatForHour
|
||||
.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles"));
|
||||
public void testUtcToLocalTimeHour_12HourFormat_returnExpectedResult() {
|
||||
final long timestamp = 1619196786769L;
|
||||
ConvertUtils.sSimpleDateFormatForHour = null;
|
||||
// Invokes the method first to create the SimpleDateFormat.
|
||||
ConvertUtils.utcToLocalTimeHour(/*timestamp=*/ 0, /*is24HourFormat=*/ false);
|
||||
ConvertUtils.sSimpleDateFormatForHour
|
||||
.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles"));
|
||||
|
||||
assertThat(ConvertUtils.utcToLocalTimeHour(timestamp))
|
||||
.isEqualTo("9 am");
|
||||
assertThat(ConvertUtils.utcToLocalTimeHour(
|
||||
timestamp, /*is24HourFormat=*/ false)).isEqualTo("9 am");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUtcToLocalTimeHour_24HourFormat_returnExpectedResult() {
|
||||
final long timestamp = 1619196786769L;
|
||||
ConvertUtils.sSimpleDateFormatForHour = null;
|
||||
// Invokes the method first to create the SimpleDateFormat.
|
||||
ConvertUtils.utcToLocalTimeHour(/*timestamp=*/ 0, /*is24HourFormat=*/ true);
|
||||
ConvertUtils.sSimpleDateFormatForHour
|
||||
.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles"));
|
||||
|
||||
assertThat(ConvertUtils.utcToLocalTimeHour(
|
||||
timestamp, /*is24HourFormat=*/ true)).isEqualTo("09");
|
||||
}
|
||||
|
||||
private static BatteryHistEntry createBatteryHistEntry(
|
||||
|
Reference in New Issue
Block a user