public static Period parsePeriod()

in scripts/src/main/java/com/gu/typesafe/config/impl/SimpleConfig.java [642:688]


    public static Period parsePeriod(String input,
                                     com.gu.typesafe.config.ConfigOrigin originForException, String pathForException) {
        String s = ConfigImplUtil.unicodeTrim(input);
        String originalUnitString = getUnits(s);
        String unitString = originalUnitString;
        String numberString = ConfigImplUtil.unicodeTrim(s.substring(0, s.length()
                - unitString.length()));
        ChronoUnit units;

        // this would be caught later anyway, but the error message
        // is more helpful if we check it here.
        if (numberString.length() == 0)
            throw new com.gu.typesafe.config.ConfigException.BadValue(originForException,
                    pathForException, "No number in period value '" + input
                    + "'");

        if (unitString.length() > 2 && !unitString.endsWith("s"))
            unitString = unitString + "s";

        // note that this is deliberately case-sensitive
        if (unitString.equals("") || unitString.equals("d") || unitString.equals("days")) {
            units = ChronoUnit.DAYS;

        } else if (unitString.equals("w") || unitString.equals("weeks")) {
            units = ChronoUnit.WEEKS;

        } else if (unitString.equals("m") || unitString.equals("mo") || unitString.equals("months")) {
            units = ChronoUnit.MONTHS;

        } else if (unitString.equals("y") || unitString.equals("years")) {
            units = ChronoUnit.YEARS;

        } else {
            throw new com.gu.typesafe.config.ConfigException.BadValue(originForException,
                    pathForException, "Could not parse time unit '"
                    + originalUnitString
                    + "' (try d, w, mo, y)");
        }

        try {
           return periodOf(Integer.parseInt(numberString), units);
        } catch (NumberFormatException e) {
            throw new com.gu.typesafe.config.ConfigException.BadValue(originForException,
                    pathForException, "Could not parse duration number '"
                    + numberString + "'");
        }
    }