Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
import dev.ikm.tinkar.terms.ConceptFacade;
import org.eclipse.collections.api.list.primitive.ImmutableLongList;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
Expand All @@ -26,8 +24,6 @@

public class FilterOptionsUtils {

public static final SimpleDateFormat SIMPLE_DATE_FORMAT = new SimpleDateFormat("MM/dd/yyyy");

public static FilterOptions loadFilterOptions(ObservableCoordinate<ViewCoordinateRecord> parentView, ViewCalculator calculator) {
FilterOptions filterOptions = new FilterOptions();

Expand Down Expand Up @@ -81,7 +77,7 @@ public static FilterOptions loadFilterOptions(ObservableCoordinate<ViewCoordinat
Date date = new Date(time);
timeOption.defaultOptions().clear();
timeOption.selectedOptions().clear();
timeOption.selectedOptions().add(SIMPLE_DATE_FORMAT.format(date));
timeOption.selectedOptions().add(String.valueOf(time));
timeOption.defaultOptions().addAll(timeOption.selectedOptions());
}
} else if (observableCoordinate instanceof ObservableLanguageCoordinate observableLanguageCoordinate) {
Expand All @@ -105,24 +101,22 @@ public static FilterOptions loadFilterOptions(ObservableCoordinate<ViewCoordinat
public static long getMillis(FilterOptions filterOptions) {
FilterOptions.Option time = filterOptions.getMainCoordinates().getTime();
if (time == null || time.selectedOptions().isEmpty()) {
return -1;
return -1L;
}

Date date;
try {
date = SIMPLE_DATE_FORMAT.parse(time.selectedOptions().getFirst());
} catch (ParseException e) {
throw new RuntimeException(e);
return Long.parseLong(time.selectedOptions().getFirst());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jperedadnr is there a situation where this could be the string "Latest" and the parseLong will throw an exception?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is in a try-catch though, so if selectedOptions contains anything but a long timestamp, it will return -1L.

Before this PR a RTE was thrown for such case, but that should be handled in a better way. If the "Latest" string should be mapped to a specific long value (like Long.MAX_VALUE), then we should pass such value.

} catch (NumberFormatException e) {
return -1L;
}
return date.getTime();
}

public static List<LocalDateTime> getTimesInUse() {
public static List<ZonedDateTime> getTimesInUse() {
ImmutableLongList times = StampService.get().getTimesInUse().toReversed();
return Arrays.stream(times.toArray())
.filter(time -> time != PREMUNDANE_TIME)
.boxed()
.map(time -> DateTimeUtil.epochToZonedDateTime(time).toLocalDateTime())
.map(DateTimeUtil::epochToZonedDateTime)
.toList();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package dev.ikm.komet.kview.controls;

import dev.ikm.komet.kview.controls.skin.RangeCalendarSkin;
import javafx.beans.property.LongProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.ReadOnlyBooleanProperty;
import javafx.beans.property.ReadOnlyBooleanWrapper;
import javafx.beans.property.SimpleLongProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.collections.FXCollections;
import javafx.collections.MapChangeListener;
Expand All @@ -12,7 +14,7 @@
import javafx.scene.control.Skin;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

Expand Down Expand Up @@ -75,6 +77,18 @@ public final void setDate(LocalDate value) {
dateProperty.set(value);
}

// timestampProperty
private final LongProperty timestampProperty = new SimpleLongProperty(this, "timestamp", -1L);
public final LongProperty timestampProperty() {
return timestampProperty;
}
public final long getTimestamp() {
return timestampProperty.get();
}
public final void setTimestamp(long value) {
timestampProperty.set(value);
}

// dateRangeListProperty
private final ObservableList<DateRange> dateRangeList = FXCollections.observableArrayList();
public final ObservableList<DateRange> dateRangeList() {
Expand All @@ -97,14 +111,14 @@ public void addRange(boolean isExcluding) {
}

// stampDatesProperty
private final ObjectProperty<List<LocalDateTime>> stampDatesProperty = new SimpleObjectProperty<>(this, "stampDates");
public final ObjectProperty<List<LocalDateTime>> stampDatesProperty() {
private final ObjectProperty<List<ZonedDateTime>> stampDatesProperty = new SimpleObjectProperty<>(this, "stampDates");
public final ObjectProperty<List<ZonedDateTime>> stampDatesProperty() {
return stampDatesProperty;
}
public final List<LocalDateTime> getStampDates() {
public final List<ZonedDateTime> getStampDates() {
return stampDatesProperty.get();
}
public final void setStampDates(List<LocalDateTime> value) {
public final void setStampDates(List<ZonedDateTime> value) {
stampDatesProperty.set(value);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package dev.ikm.komet.kview.controls.skin;

import static dev.ikm.komet.kview.controls.RangeCalendarControl.DATE_FORMATTER;
import static dev.ikm.komet.kview.controls.RangeCalendarControl.DEFAULT_DATE_PATTERN;
import dev.ikm.komet.kview.controls.DateFilterTitledPane;
import dev.ikm.komet.kview.controls.DateRange;
import dev.ikm.komet.kview.controls.FilterOptions;
import dev.ikm.komet.kview.controls.FilterOptionsUtils;
import dev.ikm.komet.kview.controls.IconRegion;
import dev.ikm.komet.kview.controls.RangeCalendarControl;
import dev.ikm.komet.kview.controls.TruncatedTextFlow;
import dev.ikm.tinkar.common.util.time.DateTimeUtil;
import javafx.collections.FXCollections;
import javafx.css.PseudoClass;
import javafx.scene.Parent;
Expand All @@ -24,8 +24,7 @@
import javafx.util.Subscription;

import java.text.MessageFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.ZonedDateTime;
import java.time.format.DateTimeParseException;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -185,7 +184,7 @@ private void setupTitledPane() {
currentOption.selectedOptions().clear();
currentOption.excludedOptions().clear();
if (calendarControl != null && calendarControl.getDate() != null) {
currentOption.selectedOptions().add(DATE_FORMATTER.format(calendarControl.getDate()));
currentOption.selectedOptions().add(String.valueOf(calendarControl.getTimestamp()));
} else if (calendarControl != null && !calendarControl.dateRangeList().isEmpty()) {
calendarControl.dateRangeList().stream()
.filter(r -> !r.exclude())
Expand Down Expand Up @@ -235,11 +234,15 @@ private void createSpecificDatePane(FilterOptions.Option option) {
contentBox.getChildren().setAll(separatorRegion, calendarControl);

if (containsDate(option.selectedOptions())) {
String value = option.selectedOptions().getFirst();
try {
LocalDate date = LocalDate.parse(option.selectedOptions().getFirst(), DateTimeFormatter.ofPattern(DEFAULT_DATE_PATTERN));
calendarControl.setDate(date);
} catch (DateTimeParseException e) {
// ignore
long timestamp = Long.parseLong(value);
calendarControl.setTimestamp(timestamp);
ZonedDateTime zonedDateTime = DateTimeUtil.epochToZonedDateTime(timestamp);
calendarControl.setDate(zonedDateTime.toLocalDate());
} catch (NumberFormatException e) {
calendarControl.setTimestamp(-1L);
calendarControl.setDate(null);
}
}
control.setMode(DateFilterTitledPane.MODE.SINGLE_DATE);
Expand Down
Loading