class StringToDurationConverter implements Converter<String, Duration> {

    static final StringToDurationConverter INSTANCE = new StringToDurationConverter();

    private static final Pattern ISO8601 = Pattern.compile("^[\\+\\-]?P.*$");

    private static final Pattern SIMPLE = Pattern.compile("^([\\+\\-]?\\d+)([a-zA-Z]{0,2})$");

    private static final Map<String, ChronoUnit> UNITS;

    static {
        Map<String, ChronoUnit> units = new LinkedHashMap<>();
        units.put("us", ChronoUnit.MICROS);
        units.put("ns", ChronoUnit.NANOS);
        units.put("ms", ChronoUnit.MILLIS);
        units.put("s", ChronoUnit.SECONDS);
        units.put("m", ChronoUnit.MINUTES);
        units.put("h", ChronoUnit.HOURS);
        units.put("d", ChronoUnit.DAYS);
        units.put("", ChronoUnit.MILLIS);
        UNITS = Collections.unmodifiableMap(units);
    }

    @Override
    public Duration convert(String source) {<FILL_FUNCTION_BODY>}

    private ChronoUnit getUnit(String value) {
        ChronoUnit unit = UNITS.get(value.toLowerCase());
        Assert.state(unit != null, "Unknown unit '" + value + "'");
        return unit;
    }
}

        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);
        }
    
<no_super_class>