Switch Utils.formatElapsedTime to use ICU's MeasureFormat
Previously, localizable strings were used instead, causing various difficulties and inconsistencies. Now we use ICU's MeasureFormat. The results for English are almost identical to the previous results (see below), and we also get higher quality and better-vetted results for other locales. Note: This also makes formatted strings shorter by eliminating zeros. For example, what was previously shown as "2d 0h 15m" is now shown as "2d 15m". Bug: 36994779 Bug: 37701311 Test: make -j RunSettingsRoboTests Change-Id: I78fd09e4e7f63f41ef88d3d3fc4ba2be15e1d812
This commit is contained in:
@@ -94,8 +94,8 @@ public class UtilsTest {
|
||||
|
||||
@Test
|
||||
public void testFormatElapsedTime_WithSeconds_ShowSeconds() {
|
||||
final double testMillis = 5 * DateUtils.MINUTE_IN_MILLIS;
|
||||
final String expectedTime = "5m 0s";
|
||||
final double testMillis = 5 * DateUtils.MINUTE_IN_MILLIS + 30 * DateUtils.SECOND_IN_MILLIS;
|
||||
final String expectedTime = "5m 30s";
|
||||
|
||||
assertThat(Utils.formatElapsedTime(mContext, testMillis, true).toString()).isEqualTo(
|
||||
expectedTime);
|
||||
@@ -103,8 +103,8 @@ public class UtilsTest {
|
||||
|
||||
@Test
|
||||
public void testFormatElapsedTime_NoSeconds_DoNotShowSeconds() {
|
||||
final double testMillis = 5 * DateUtils.MINUTE_IN_MILLIS;
|
||||
final String expectedTime = "5m";
|
||||
final double testMillis = 5 * DateUtils.MINUTE_IN_MILLIS + 30 * DateUtils.SECOND_IN_MILLIS;
|
||||
final String expectedTime = "6m";
|
||||
|
||||
assertThat(Utils.formatElapsedTime(mContext, testMillis, false).toString()).isEqualTo(
|
||||
expectedTime);
|
||||
@@ -120,6 +120,33 @@ public class UtilsTest {
|
||||
expectedTime);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormatElapsedTime_ZeroFieldsInTheMiddleDontShow() {
|
||||
final double testMillis = 2 * DateUtils.DAY_IN_MILLIS + 15 * DateUtils.MINUTE_IN_MILLIS;
|
||||
final String expectedTime = "2d 15m";
|
||||
|
||||
assertThat(Utils.formatElapsedTime(mContext, testMillis, false).toString()).isEqualTo(
|
||||
expectedTime);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormatElapsedTime_FormatZero_WithSeconds() {
|
||||
final double testMillis = 0;
|
||||
final String expectedTime = "0s";
|
||||
|
||||
assertThat(Utils.formatElapsedTime(mContext, testMillis, true).toString()).isEqualTo(
|
||||
expectedTime);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormatElapsedTime_FormatZero_NoSeconds() {
|
||||
final double testMillis = 0;
|
||||
final String expectedTime = "0m";
|
||||
|
||||
assertThat(Utils.formatElapsedTime(mContext, testMillis, false).toString()).isEqualTo(
|
||||
expectedTime);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormatElapsedTime_onlyContainsMinute_hasTtsSpan() {
|
||||
final double testMillis = 15 * DateUtils.MINUTE_IN_MILLIS;
|
||||
|
Reference in New Issue
Block a user