TimeUtil { public static String toCloudDuration(ReadableDuration duration) { long millis = duration.getMillis(); long seconds = millis / 1000; millis = millis % 1000; if (millis == 0) { return String.format("%ds", seconds); } else { return String.format("%d.%03ds", seconds, millis); } } private  TimeUtil(); static String toCloudTime(ReadableInstant instant); static @Nullable Instant fromCloudTime(String time); static String toCloudDuration(ReadableDuration duration); static @Nullable Duration fromCloudDuration(String duration);  }
@Test public void toCloudDurationShouldPrintDurationStrings() { assertEquals("0s", toCloudDuration(Duration.ZERO)); assertEquals("4s", toCloudDuration(Duration.millis(4000))); assertEquals("4.001s", toCloudDuration(Duration.millis(4001))); }