DateTimeExt { public static String toTimeUnitString(Duration duration) { return toTimeUnitString(Durations.toMillis(duration)); } private  DateTimeExt(); static ZoneId toZoneId(String timeZoneName); static ZoneOffset toZoneOffset(String timeZoneName); static String toUtcDateTimeString(long msSinceEpoch); static String toLocalDateTimeString(long msSinceEpoch); static String toTimeUnitAbbreviation(TimeUnit timeUnit); static String toTimeUnitString(Duration duration); static String toTimeUnitString(long timeMs); static String toRateString(long interval, long itemsPerInterval, TimeUnit timeUnit, String rateType);  }
@Test public void testTime() { long msDuration = 123; assertThat(toTimeUnitString(msDuration)).isEqualTo("123ms"); long secDuration = 3 * 1000 + 123; assertThat(toTimeUnitString(secDuration)).isEqualTo("3s 123ms"); long minDuration = (2 * 60 + 3) * 1000 + 123; assertThat(toTimeUnitString(minDuration)).isEqualTo("2min 3s 123ms"); long hourDuration = ((1 * 60 + 2) * 60 + 3) * 1000 + 123; assertThat(toTimeUnitString(hourDuration)).isEqualTo("1h 2min 3s 123ms"); long oneSecond = 1 * 1000; assertThat(toTimeUnitString(oneSecond)).isEqualTo("1s"); long oneMillis = 1; assertThat(toTimeUnitString(oneMillis)).isEqualTo("1ms"); long zeroMillis = 0; assertThat(toTimeUnitString(zeroMillis)).isEqualTo("0ms"); long twoDays = TimeUnit.DAYS.toMillis(2); assertThat(toTimeUnitString(twoDays)).isEqualTo("2d"); }