@Test public void convertWhenSimpleHoursShouldReturnDuration() { assertThat(convert("10h")).isEqualTo(Duration.ofHours(10)); assertThat(convert("10H")).isEqualTo(Duration.ofHours(10)); assertThat(convert("+10h")).isEqualTo(Duration.ofHours(10)); assertThat(convert("-10h")).isEqualTo(Duration.ofHours(-10)); }
@Override public Duration convert(String source) { try { if (ISO8601.matcher(source).matches()) { return Duration.parse(source); } Matcher matcher = SIMPLE.matcher(source); Assert.state(matcher.matches(), "'" + source + "' is not a valid duration"); long amount = Long.parseLong(matcher.group(1)); ChronoUnit unit = getUnit(matcher.group(2)); return Duration.of(amount, unit); } catch (Exception ex) { throw new IllegalStateException("'" + source + "' is not a valid duration", ex); } }
StringToDurationConverter implements Converter<String, Duration> { @Override public Duration convert(String source) { try { if (ISO8601.matcher(source).matches()) { return Duration.parse(source); } Matcher matcher = SIMPLE.matcher(source); Assert.state(matcher.matches(), "'" + source + "' is not a valid duration"); long amount = Long.parseLong(matcher.group(1)); ChronoUnit unit = getUnit(matcher.group(2)); return Duration.of(amount, unit); } catch (Exception ex) { throw new IllegalStateException("'" + source + "' is not a valid duration", ex); } } }
StringToDurationConverter implements Converter<String, Duration> { @Override public Duration convert(String source) { try { if (ISO8601.matcher(source).matches()) { return Duration.parse(source); } Matcher matcher = SIMPLE.matcher(source); Assert.state(matcher.matches(), "'" + source + "' is not a valid duration"); long amount = Long.parseLong(matcher.group(1)); ChronoUnit unit = getUnit(matcher.group(2)); return Duration.of(amount, unit); } catch (Exception ex) { throw new IllegalStateException("'" + source + "' is not a valid duration", ex); } }  }
StringToDurationConverter implements Converter<String, Duration> { @Override public Duration convert(String source) { try { if (ISO8601.matcher(source).matches()) { return Duration.parse(source); } Matcher matcher = SIMPLE.matcher(source); Assert.state(matcher.matches(), "'" + source + "' is not a valid duration"); long amount = Long.parseLong(matcher.group(1)); ChronoUnit unit = getUnit(matcher.group(2)); return Duration.of(amount, unit); } catch (Exception ex) { throw new IllegalStateException("'" + source + "' is not a valid duration", ex); } }  @Override Duration convert(String source); }
StringToDurationConverter implements Converter<String, Duration> { @Override public Duration convert(String source) { try { if (ISO8601.matcher(source).matches()) { return Duration.parse(source); } Matcher matcher = SIMPLE.matcher(source); Assert.state(matcher.matches(), "'" + source + "' is not a valid duration"); long amount = Long.parseLong(matcher.group(1)); ChronoUnit unit = getUnit(matcher.group(2)); return Duration.of(amount, unit); } catch (Exception ex) { throw new IllegalStateException("'" + source + "' is not a valid duration", ex); } }  @Override Duration convert(String source);  }