@Test public void testParsePositive() { assertEquals(Duration.ofSeconds(20), parsePositive("PT20S")); assertEquals(Duration.ofSeconds(20), parsePositive("20s")); assertEquals(Duration.ofDays(-123), parsePositive(" ")); assertEquals(Duration.ofDays(-123), parsePositive("0s")); assertEquals(Duration.ofDays(-123), parsePositive("-PT20S")); assertEquals(Duration.ofDays(-123), parsePositive("1 day")); }
public static Duration parsePositive(String value, Duration defaultDuration) { if (isBlank(value)) { return defaultDuration; } try { Duration duration = parse(value); if (duration.isZero() || duration.isNegative()) { return defaultDuration; } else { return duration; } } catch (DateTimeParseException e) { return defaultDuration; } }
DurationUtils { public static Duration parsePositive(String value, Duration defaultDuration) { if (isBlank(value)) { return defaultDuration; } try { Duration duration = parse(value); if (duration.isZero() || duration.isNegative()) { return defaultDuration; } else { return duration; } } catch (DateTimeParseException e) { return defaultDuration; } } }
DurationUtils { public static Duration parsePositive(String value, Duration defaultDuration) { if (isBlank(value)) { return defaultDuration; } try { Duration duration = parse(value); if (duration.isZero() || duration.isNegative()) { return defaultDuration; } else { return duration; } } catch (DateTimeParseException e) { return defaultDuration; } } private  DurationUtils(); }
DurationUtils { public static Duration parsePositive(String value, Duration defaultDuration) { if (isBlank(value)) { return defaultDuration; } try { Duration duration = parse(value); if (duration.isZero() || duration.isNegative()) { return defaultDuration; } else { return duration; } } catch (DateTimeParseException e) { return defaultDuration; } } private  DurationUtils(); static Duration parse(String value); static Duration parsePositive(String value, Duration defaultDuration); }
DurationUtils { public static Duration parsePositive(String value, Duration defaultDuration) { if (isBlank(value)) { return defaultDuration; } try { Duration duration = parse(value); if (duration.isZero() || duration.isNegative()) { return defaultDuration; } else { return duration; } } catch (DateTimeParseException e) { return defaultDuration; } } private  DurationUtils(); static Duration parse(String value); static Duration parsePositive(String value, Duration defaultDuration); static final Pattern DURATION_SIMPLE_FORMAT; }