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;
}
Aggregations