Search in sources :

Example 51 with DateTimeParseException

use of java.time.format.DateTimeParseException in project knime-core by knime.

the class LoopStartWindowNodeModel method getTemporalAmount.

/**
 * Gets the temporal amount from the given string which can be either a Duration or a Period.
 *
 * @param amount string that shall be parsed
 * @return TemporalAmount of the string or {@code null} if it cannot be parsed to Duration or Period.
 */
private TemporalAmount getTemporalAmount(String amount) {
    /* Change milliseconds to seconds to allow parsing. */
    if (amount.endsWith(Unit.MILLISECONDS.getUnitLetter())) {
        String tempAmount = amount.substring(0, amount.length() - Unit.MILLISECONDS.getUnitLetter().length());
        Double temp = Double.parseDouble(tempAmount);
        temp /= 1000;
        amount = temp + Unit.SECONDS.getUnitLetter();
    }
    try {
        return DurationPeriodFormatUtils.parseDuration(amount);
    } catch (DateTimeParseException e) {
        try {
            return DurationPeriodFormatUtils.parsePeriod(amount);
        } catch (DateTimeException e2) {
        }
    }
    return null;
}
Also used : DateTimeParseException(java.time.format.DateTimeParseException) DateTimeException(java.time.DateTimeException) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString)

Aggregations

DateTimeParseException (java.time.format.DateTimeParseException)51 DateTimeFormatter (java.time.format.DateTimeFormatter)17 LocalDate (java.time.LocalDate)15 Test (org.testng.annotations.Test)14 TemporalAccessor (java.time.temporal.TemporalAccessor)13 LocalDateTime (java.time.LocalDateTime)11 DateTimeFormatterBuilder (java.time.format.DateTimeFormatterBuilder)10 Instant (java.time.Instant)7 Duration (java.time.Duration)5 ZonedDateTime (java.time.ZonedDateTime)5 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)5 Period (java.time.Period)4 LocalTime (java.time.LocalTime)3 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)3 DataflowException (edu.uci.ics.texera.api.exception.DataflowException)2 ParseException (java.text.ParseException)2 DateTimeException (java.time.DateTimeException)2 ZoneId (java.time.ZoneId)2 ResolverStyle (java.time.format.ResolverStyle)2 Temporal (java.time.temporal.Temporal)2