use of java.time.DateTimeException in project hive by apache.
the class TimestampTZUtil method parse.
public static TimestampTZ parse(String s, ZoneId defaultTimeZone) {
// need to handle offset with single digital hour, see JDK-8066806
s = handleSingleDigitHourOffset(s);
ZonedDateTime zonedDateTime;
try {
zonedDateTime = ZonedDateTime.parse(s, FORMATTER);
} catch (DateTimeParseException e) {
// try to be more tolerant
// if the input is invalid instead of incomplete, we'll hit exception here again
TemporalAccessor accessor = FORMATTER.parse(s);
// LocalDate must be present
LocalDate localDate = LocalDate.from(accessor);
LocalTime localTime;
ZoneId zoneId;
try {
localTime = LocalTime.from(accessor);
} catch (DateTimeException e1) {
localTime = DEFAULT_LOCAL_TIME;
}
try {
zoneId = ZoneId.from(accessor);
} catch (DateTimeException e2) {
if (defaultTimeZone == null) {
throw new DateTimeException("Time Zone not available");
}
zoneId = defaultTimeZone;
}
zonedDateTime = ZonedDateTime.of(localDate, localTime, zoneId);
}
if (defaultTimeZone == null) {
return new TimestampTZ(zonedDateTime);
}
return new TimestampTZ(zonedDateTime.withZoneSameInstant(defaultTimeZone));
}
use of java.time.DateTimeException in project knime-core by knime.
the class StringToDateTimeNodeDialog method guessFormat.
private void guessFormat(final String preview) {
final Collection<String> formats = StringToDateTimeNodeModel.createPredefinedFormats();
for (final String format : formats) {
final DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format);
try {
ZonedDateTime.parse(preview, formatter);
m_typeCombobox.setSelectedItem(DateTimeType.ZONED_DATE_TIME);
m_formatModel.setStringValue(format);
return;
} catch (DateTimeException e) {
}
try {
LocalDateTime.parse(preview, formatter);
m_typeCombobox.setSelectedItem(DateTimeType.LOCAL_DATE_TIME);
m_formatModel.setStringValue(format);
return;
} catch (DateTimeException e) {
}
try {
LocalDate.parse(preview, formatter);
m_typeCombobox.setSelectedItem(DateTimeType.LOCAL_DATE);
m_formatModel.setStringValue(format);
return;
} catch (DateTimeException e) {
}
try {
LocalTime.parse(preview, formatter);
m_typeCombobox.setSelectedItem(DateTimeType.LOCAL_TIME);
m_formatModel.setStringValue(format);
return;
} catch (DateTimeException e) {
}
}
m_typeFormatWarningLabel.setText("No suitable format found!");
}
use of java.time.DateTimeException in project knime-core by knime.
the class DateTimeBasedRowFilterNodeModel method calculateEndDateTime.
/**
* Calculates the ending point if period/duration or granularity is selected. Otherwise output will be the same as
* input (endDateTime).
*
* @param startDateTime starting point
* @param endDateTime current ending point
* @return
*/
private Temporal calculateEndDateTime(final Temporal startDateTime, final Temporal endDateTime) throws ArithmeticException, DateTimeException {
Temporal end = endDateTime;
if (m_endSelection.getStringValue().equals(EndMode.Duration.name())) {
try {
end = startDateTime.plus(DurationPeriodFormatUtils.parsePeriod(m_periodValueModel.getStringValue()));
} catch (DateTimeException e1) {
end = startDateTime.plus(DurationPeriodFormatUtils.parseDuration(m_periodValueModel.getStringValue()));
}
}
if (m_endSelection.getStringValue().equals(EndMode.Numerical.name())) {
final TemporalAmount amount = Granularity.fromString(m_granularityModel.getStringValue()).getPeriodOrDuration(m_numericalValueModel.getIntValue());
end = startDateTime.plus(amount);
}
return end;
}
use of java.time.DateTimeException 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;
}
use of java.time.DateTimeException in project drools by kiegroup.
the class DayDiffFunction method invoke.
public FEELFnResult<BigDecimal> invoke(@ParameterName("datetime1") String datetime1, @ParameterName("datetime2") String datetime2) {
if (datetime1 == null) {
return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "datetime1", "cannot be null"));
}
if (datetime2 == null) {
return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "datetime2", "cannot be null"));
}
try {
TemporalAccessor dt1 = BuiltInFunctions.getFunction(DateAndTimeFunction.class).invoke(datetime1).cata(BuiltInType.justNull(), Function.identity());
TemporalAccessor dt2 = BuiltInFunctions.getFunction(DateAndTimeFunction.class).invoke(datetime2).cata(BuiltInType.justNull(), Function.identity());
return invoke(dt1, dt2);
} catch (DateTimeException e) {
return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "datetime", "invalid 'date' or 'date and time' parameter", e));
}
}
Aggregations