Skip to content

Commit

Permalink
PE0025 Update InstantPicker
Browse files Browse the repository at this point in the history
  • Loading branch information
N0tSure committed Apr 6, 2020
1 parent 46e1a0b commit 4404cd7
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/main/java/com/artemsirosh/hitbtc/view/InstantPicker.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import java.time.*;
import java.util.Objects;
import java.util.Optional;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
Expand Down Expand Up @@ -36,7 +35,7 @@ public class InstantPicker extends CustomField<Instant> {
* @param label of field
* @param thresholdAdjuster adjust minimal or maximal value of field
*/
public InstantPicker(String label, BiConsumer<LocalDate, LocalTime> thresholdAdjuster) {
public InstantPicker(String label, ThresholdAdjuster thresholdAdjuster) {
final DatePicker datePicker = new DatePicker();
final TimePicker timePicker = new TimePicker();
final ZoneOffset utcOffset = ZoneOffset.UTC;
Expand All @@ -54,12 +53,10 @@ public InstantPicker(String label, BiConsumer<LocalDate, LocalTime> thresholdAdj
timePicker.setValue(dateTime.toLocalTime());
});

this.listener = event -> {
Optional.ofNullable(event.getValue()).ifPresent(instant -> {
final OffsetDateTime dt = instantToDateTime.apply(instant);
thresholdAdjuster.accept(dt.toLocalDate(), dt.toLocalTime());
});
};
this.listener = event -> Optional.ofNullable(event.getValue()).ifPresent(instant -> {
final OffsetDateTime dt = instantToDateTime.apply(instant);
thresholdAdjuster.adjust(dt.toLocalDate(), dt.toLocalTime(), datePicker, timePicker);
});

this.setLabel(label);
this.add(datePicker, timePicker);
Expand All @@ -82,4 +79,10 @@ protected Instant generateModelValue() {
protected void setPresentationValue(Instant newPresentationValue) {
modelValueSetter.accept(newPresentationValue);
}

@FunctionalInterface
public interface ThresholdAdjuster {

void adjust(LocalDate date, LocalTime time, DatePicker datePicker, TimePicker timePicker);
}
}

0 comments on commit 4404cd7

Please sign in to comment.