public static String toCloudDuration(ReadableDuration duration) {
    // Note that since Joda objects use millisecond resolution, we always
    // produce either no fractional seconds or fractional seconds with
    // millisecond resolution.
    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);
    }
  }
@Test
  public void toCloudDurationShouldPrintDurationStrings() {
    assertEquals("0s", toCloudDuration(Duration.ZERO));
    assertEquals("4s", toCloudDuration(Duration.millis(4000)));
    assertEquals("4.001s", toCloudDuration(Duration.millis(4001)));
  }