public static Duration parse(String input) throws IllegalArgumentException {
        Matcher matcher = PATTERN.matcher(input);

        while (matcher.find()) {
            if (matcher.group() == null || matcher.group().isEmpty()) {
                continue;
            }

            Duration duration = Duration.ZERO;
            for (int i = 0; i < UNITS.length; i++) {
                ChronoUnit unit = UNITS[i];
                int g = i + 1;

                if (matcher.group(g) != null && !matcher.group(g).isEmpty()) {
                    int n = Integer.parseInt(matcher.group(g));
                    if (n > 0) {
                        duration = duration.plus(unit.getDuration().multipliedBy(n));
                    }
                }
            }

            return duration;
        }

        throw new IllegalArgumentException("unable to parse duration: " + input);
    }
Parses a {@link Duration} from a string.

@param input the input string
@return the parsed duration
@throws IllegalArgumentException if parsing fails
helper/src/main/java/me/lucko/helper/time/DurationParser.java