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

Commit 93fbae34 authored by Bjorn Bringert's avatar Bjorn Bringert Committed by Android (Google) Code Review
Browse files

Merge "Don't drop zeros in the second position in formatDuration()"

parents 4ffb3e09 901b3796
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -158,18 +158,17 @@ public class TimeUtils {
    static private int printField(char[] formatStr, int amt, char suffix, int pos,
            boolean always, int zeropad) {
        if (always || amt > 0) {
            final int startPos = pos;
            if ((always && zeropad >= 3) || amt > 99) {
                int dig = amt/100;
                formatStr[pos] = (char)(dig + '0');
                pos++;
                always = true;
                amt -= (dig*100);
            }
            if ((always && zeropad >= 2) || amt > 9) {
            if ((always && zeropad >= 2) || amt > 9 || startPos != pos) {
                int dig = amt/10;
                formatStr[pos] = (char)(dig + '0');
                pos++;
                always = true;
                amt -= (dig*10);
            }
            formatStr[pos] = (char)(amt + '0');
+18 −0
Original line number Diff line number Diff line
@@ -429,4 +429,22 @@ public class TimeUtilsTest extends TestCase {
                                     c.getTimeInMillis(),
                                     country);
    }

    public void testFormatDuration() {
        assertFormatDuration("0", 0);
        assertFormatDuration("-1ms", -1);
        assertFormatDuration("+1ms", 1);
        assertFormatDuration("+10ms", 10);
        assertFormatDuration("+100ms", 100);
        assertFormatDuration("+101ms", 101);
        assertFormatDuration("+330ms", 330);
        assertFormatDuration("+1s330ms", 1330);
        assertFormatDuration("+10s24ms", 10024);
    }

    private void assertFormatDuration(String expected, long duration) {
        StringBuilder sb = new StringBuilder();
        TimeUtils.formatDuration(duration, sb);
        assertEquals("formatDuration(" + duration + ")", expected, sb.toString());
    }
}