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

Commit 128f5630 authored by Lei Yu's avatar Lei Yu
Browse files

Change the time format to short

So it will show "2 days, 15 hr, 2 min" instead of "2d 15h 2m"

Bug: 76113036
Test: RunSettingsLibRoboTests
Change-Id: I31df2ac8e1ebc0616ef58ea2d21a50ca9788b392
parent 9bea5047
Loading
Loading
Loading
Loading
+6 −5
Original line number Diff line number Diff line
@@ -42,7 +42,8 @@ public class StringUtil {

    /**
     * Returns elapsed time for the given millis, in the following format:
    * 2d 5h 40m 29s
     * 2 days, 5 hr, 40 min, 29 sec
     *
     * @param context     the application context
     * @param millis      the elapsed time in milli seconds
     * @param withSeconds include seconds?
@@ -92,7 +93,7 @@ public class StringUtil {

        final Locale locale = context.getResources().getConfiguration().locale;
        final MeasureFormat measureFormat = MeasureFormat.getInstance(
                locale, FormatWidth.NARROW);
                locale, FormatWidth.SHORT);
        sb.append(measureFormat.formatMeasures(measureArray));

        if (measureArray.length == 1 && MeasureUnit.MINUTE.equals(measureArray[0].getUnit())) {
+4 −4
Original line number Diff line number Diff line
@@ -137,9 +137,9 @@ public class PowerUtilTest {
                true /* basedOnUsage */);

        // shortened string should not have percentage
        assertThat(info).isEqualTo("Less than 15m remaining");
        assertThat(info).isEqualTo("Less than 15 min remaining");
        // Add percentage to string when provided
        assertThat(info2).isEqualTo("Less than 15m remaining (10%)");
        assertThat(info2).isEqualTo("Less than 15 min remaining (10%)");
    }

    @Test
@@ -154,9 +154,9 @@ public class PowerUtilTest {
                false /* basedOnUsage */);

        // We only add special mention for the long string
        assertThat(info).isEqualTo("About 1d 6h left based on your usage");
        assertThat(info).isEqualTo("About 1 day, 6 hr left based on your usage");
        // shortened string should not have extra text
        assertThat(info2).isEqualTo("About 1d 6h left (10%)");
        assertThat(info2).isEqualTo("About 1 day, 6 hr left (10%)");
    }

    @Test
+6 −6
Original line number Diff line number Diff line
@@ -43,7 +43,7 @@ public class StringUtilTest {
    @Test
    public void testFormatElapsedTime_WithSeconds_ShowSeconds() {
        final double testMillis = 5 * DateUtils.MINUTE_IN_MILLIS + 30 * DateUtils.SECOND_IN_MILLIS;
        final String expectedTime = "5m 30s";
        final String expectedTime = "5 min, 30 sec";

        assertThat(StringUtil.formatElapsedTime(mContext, testMillis, true).toString())
                .isEqualTo(expectedTime);
@@ -52,7 +52,7 @@ public class StringUtilTest {
    @Test
    public void testFormatElapsedTime_NoSeconds_DoNotShowSeconds() {
        final double testMillis = 5 * DateUtils.MINUTE_IN_MILLIS + 30 * DateUtils.SECOND_IN_MILLIS;
        final String expectedTime = "6m";
        final String expectedTime = "6 min";

        assertThat(StringUtil.formatElapsedTime(mContext, testMillis, false).toString())
                .isEqualTo(expectedTime);
@@ -62,7 +62,7 @@ public class StringUtilTest {
    public void testFormatElapsedTime_TimeMoreThanOneDay_ShowCorrectly() {
        final double testMillis = 2 * DateUtils.DAY_IN_MILLIS
                + 4 * DateUtils.HOUR_IN_MILLIS + 15 * DateUtils.MINUTE_IN_MILLIS;
        final String expectedTime = "2d 4h 15m";
        final String expectedTime = "2 days, 4 hr, 15 min";

        assertThat(StringUtil.formatElapsedTime(mContext, testMillis, false).toString())
                .isEqualTo(expectedTime);
@@ -71,7 +71,7 @@ public class StringUtilTest {
    @Test
    public void testFormatElapsedTime_ZeroFieldsInTheMiddleDontShow() {
        final double testMillis = 2 * DateUtils.DAY_IN_MILLIS + 15 * DateUtils.MINUTE_IN_MILLIS;
        final String expectedTime = "2d 15m";
        final String expectedTime = "2 days, 15 min";

        assertThat(StringUtil.formatElapsedTime(mContext, testMillis, false).toString())
                .isEqualTo(expectedTime);
@@ -80,7 +80,7 @@ public class StringUtilTest {
    @Test
    public void testFormatElapsedTime_FormatZero_WithSeconds() {
        final double testMillis = 0;
        final String expectedTime = "0s";
        final String expectedTime = "0 sec";

        assertThat(StringUtil.formatElapsedTime(mContext, testMillis, true).toString())
                .isEqualTo(expectedTime);
@@ -89,7 +89,7 @@ public class StringUtilTest {
    @Test
    public void testFormatElapsedTime_FormatZero_NoSeconds() {
        final double testMillis = 0;
        final String expectedTime = "0m";
        final String expectedTime = "0 min";

        assertThat(StringUtil.formatElapsedTime(mContext, testMillis, false).toString())
                .isEqualTo(expectedTime);