public static Duration parseDuration(String text) {
        checkNotNull(text);

        final String trimmed = text.trim();
        checkArgument(!trimmed.isEmpty(), "argument is an empty- or whitespace-only string");

        final int len = trimmed.length();
        int pos = 0;

        char current;
        while (pos < len && (current = trimmed.charAt(pos)) >= '0' && current <= '9') {
            pos++;
        }

        final String number = trimmed.substring(0, pos);
        final String unitLabel = trimmed.substring(pos).trim().toLowerCase(Locale.US);

        if (number.isEmpty()) {
            throw new NumberFormatException("text does not start with a number");
        }

        final BigInteger value;
        try {
            value = new BigInteger(number); // this throws a NumberFormatException
        } catch (NumberFormatException e) {
            throw new IllegalArgumentException(
                    "The value '" + number + "' cannot be represented as an integer number.", e);
        }

        final ChronoUnit unit;
        if (unitLabel.isEmpty()) {
            unit = ChronoUnit.MILLIS;
        } else {
            unit = LABEL_TO_UNIT_MAP.get(unitLabel);
        }
        if (unit == null) {
            throw new IllegalArgumentException(
                    "Time interval unit label '"
                            + unitLabel
                            + "' does not match any of the recognized units: "
                            + TimeUnit.getAllUnits());
        }

        try {
            return convertBigIntToDuration(value, unit);
        } catch (ArithmeticException e) {
            throw new IllegalArgumentException(
                    "The value '"
                            + number
                            + "' cannot be represented as java.time.Duration (numeric overflow).",
                    e);
        }
    }
@Test
    void testParseDurationInvalid() {
        // null
        assertThatThrownBy(() -> TimeUtils.parseDuration(null))
                .isInstanceOf(NullPointerException.class);

        // empty
        assertThatThrownBy(() -> TimeUtils.parseDuration(""))
                .isInstanceOf(IllegalArgumentException.class);

        // blank
        assertThatThrownBy(() -> TimeUtils.parseDuration("     "))
                .isInstanceOf(IllegalArgumentException.class);

        // no number
        assertThatThrownBy(() -> TimeUtils.parseDuration("foobar or fubar or foo bazz"))
                .isInstanceOf(IllegalArgumentException.class);

        // wrong unit
        assertThatThrownBy(() -> TimeUtils.parseDuration("16 gjah"))
                .isInstanceOf(IllegalArgumentException.class);

        // multiple numbers
        assertThatThrownBy(() -> TimeUtils.parseDuration("16 16 17 18 ms"))
                .isInstanceOf(IllegalArgumentException.class);

        // negative number
        assertThatThrownBy(() -> TimeUtils.parseDuration("-100 ms"))
                .isInstanceOf(IllegalArgumentException.class);
    }