use of org.knime.time.util.Granularity in project knime-core by knime.
the class DateTimeDifferenceNodeModel method calculateTime.
private DataCell calculateTime(final DataCell cell, final DataCell referenceCell, final ZonedDateTime fixedDateTime) {
if (cell.isMissing()) {
return new MissingCell("Cell for calculating difference is missing.");
} else if (fixedDateTime == null && referenceCell.isMissing()) {
return new MissingCell("Reference cell for calculating difference is missing.");
}
final Temporal temporal1;
final Temporal temporal2;
if (cell instanceof ZonedDateTimeValue) {
temporal1 = ((ZonedDateTimeValue) cell).getZonedDateTime();
temporal2 = fixedDateTime == null ? ((ZonedDateTimeValue) referenceCell).getZonedDateTime() : fixedDateTime;
} else if (cell instanceof LocalDateTimeValue) {
temporal1 = ((LocalDateTimeValue) cell).getLocalDateTime();
temporal2 = fixedDateTime == null ? ((LocalDateTimeValue) referenceCell).getLocalDateTime() : fixedDateTime.toLocalDateTime();
} else {
temporal1 = ((LocalTimeValue) cell).getLocalTime();
temporal2 = fixedDateTime == null ? ((LocalTimeValue) referenceCell).getLocalTime() : fixedDateTime.toLocalTime();
}
if (m_calculationSelectModel.getStringValue().equals(OutputMode.Duration.name())) {
final Duration diffDuration = Duration.between(temporal1, temporal2);
return DurationCellFactory.create(diffDuration);
} else {
final Granularity granularity = Granularity.fromString(m_granularityModel.getStringValue());
return LongCellFactory.create(granularity.between(temporal1, temporal2));
}
}
Aggregations