/** * Return the string value of the Duration. * <br> * Example : encode(Duration.encode("9d 10h")) -> "10d2h" */ public String encode(Duration duration) { return duration.encode(HOURS_IN_DAY); }
@CheckForNull private static String sanitizeValue(String label, @Nullable String s) { if (StringUtils.isNotBlank(s)) { try { Duration duration = Duration.decode(s, HOURS_IN_DAY); return duration.encode(HOURS_IN_DAY); } catch (Exception e) { throw new IllegalArgumentException(String.format("Invalid %s: %s (%s)", label, s, e.getMessage()), e); } } return null; }
@Test public void encode() { assertThat(Duration.create(2 * ONE_DAY_IN_MINUTES + 5 * ONE_HOUR_IN_MINUTES + 46 * ONE_MINUTE).encode(HOURS_IN_DAY)).isEqualTo("2d5h46min"); assertThat(Duration.create(ONE_DAY_IN_MINUTES).encode(HOURS_IN_DAY)).isEqualTo("1d"); assertThat(Duration.create(ONE_HOUR_IN_MINUTES).encode(HOURS_IN_DAY)).isEqualTo("1h"); assertThat(Duration.create(HOURS_IN_DAY * ONE_HOUR_IN_MINUTES).encode(HOURS_IN_DAY)).isEqualTo("1d"); assertThat(Duration.create(ONE_MINUTE).encode(HOURS_IN_DAY)).isEqualTo("1min"); assertThat(Duration.create(0).encode(HOURS_IN_DAY)).isEqualTo("0min"); }
/** * Return the string value of the Duration. * <br> * Example : encode(Duration.encode("9d 10h")) -> "10d2h" */ public String encode(Duration duration) { return duration.encode(HOURS_IN_DAY); }
/** * Return the string value of the Duration. * <br> * Example : encode(Duration.encode("9d 10h")) -> "10d2h" (if sonar.technicalDebt.hoursInDay property is set to 8) */ public String encode(Duration duration) { return duration.encode(hoursInDay()); }
@CheckForNull private String sanitizeValue(String label, @Nullable String s) { if (StringUtils.isNotBlank(s)) { try { Duration duration = Duration.decode(s, HOURS_IN_DAY); return duration.encode(HOURS_IN_DAY); } catch (Exception e) { throw new IllegalArgumentException(String.format("Invalid %s: %s (%s)", label, s, e.getMessage()), e); } } return null; }
@CheckForNull private static String sanitizeValue(String label, @Nullable String s) { if (StringUtils.isNotBlank(s)) { try { Duration duration = Duration.decode(s, HOURS_IN_DAY); return duration.encode(HOURS_IN_DAY); } catch (Exception e) { throw new IllegalArgumentException(String.format("Invalid %s: %s (%s)", label, s, e.getMessage()), e); } } return null; }