ErrorProne: fix sampler/JavaTimeDefaultTimeZone

This commit is contained in:
mkpaz 2023-02-09 15:38:44 +04:00
parent 6920f98ca4
commit dae2ab5a30
4 changed files with 42 additions and 32 deletions

@ -30,6 +30,7 @@ import org.kordamp.ikonli.material2.Material2AL;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalTime; import java.time.LocalTime;
import java.time.ZoneId;
import java.time.chrono.HijrahChronology; import java.time.chrono.HijrahChronology;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.Objects; import java.util.Objects;
@ -42,7 +43,7 @@ import static javafx.scene.layout.GridPane.REMAINING;
public class DatePickerPage extends AbstractPage { public class DatePickerPage extends AbstractPage {
public static final String NAME = "DatePicker"; public static final String NAME = "DatePicker";
private static final LocalDate TODAY = LocalDate.now(); private static final LocalDate TODAY = LocalDate.now(ZoneId.systemDefault());
private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ISO_DATE; private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ISO_DATE;
private static final DateTimeFormatter TIME_FORMATTER = DateTimeFormatter.ofPattern("HH:mm:ss"); private static final DateTimeFormatter TIME_FORMATTER = DateTimeFormatter.ofPattern("HH:mm:ss");
private static final String DATE_FORMATTER_PROMPT = "yyyy-MM-dd"; private static final String DATE_FORMATTER_PROMPT = "yyyy-MM-dd";
@ -227,10 +228,14 @@ public class DatePickerPage extends AbstractPage {
private static class Clock extends VBox { private static class Clock extends VBox {
public Clock() { public Clock() {
var clockLabel = new Label(TIME_FORMATTER.format(LocalTime.now())); var clockLabel = new Label(
TIME_FORMATTER.format(LocalTime.now(ZoneId.systemDefault()))
);
clockLabel.getStyleClass().add(Styles.TITLE_2); clockLabel.getStyleClass().add(Styles.TITLE_2);
var dateLabel = new Label(DateTimeFormatter.ofPattern("EEEE, LLLL dd, yyyy").format(LocalDate.now())); var dateLabel = new Label(
DateTimeFormatter.ofPattern("EEEE, LLLL dd, yyyy").format(LocalDate.now(ZoneId.systemDefault()))
);
setStyle(""" setStyle("""
-fx-border-width: 0 0 0.5 0; -fx-border-width: 0 0 0.5 0;
@ -241,7 +246,9 @@ public class DatePickerPage extends AbstractPage {
var t = new Timeline(new KeyFrame( var t = new Timeline(new KeyFrame(
Duration.seconds(1), Duration.seconds(1),
e -> clockLabel.setText(TIME_FORMATTER.format(LocalTime.now())) e -> clockLabel.setText(
TIME_FORMATTER.format(LocalTime.now(ZoneId.systemDefault()))
)
)); ));
t.setCycleCount(Animation.INDEFINITE); t.setCycleCount(Animation.INDEFINITE);
t.playFromStart(); t.playFromStart();

@ -17,6 +17,7 @@ import org.kordamp.ikonli.feather.Feather;
import org.kordamp.ikonli.javafx.FontIcon; import org.kordamp.ikonli.javafx.FontIcon;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.ZoneId;
import java.util.stream.IntStream; import java.util.stream.IntStream;
import static atlantafx.base.theme.Styles.*; import static atlantafx.base.theme.Styles.*;
@ -214,7 +215,7 @@ public class OverviewPage extends AbstractPage {
var datePicker = new DatePicker(); var datePicker = new DatePicker();
datePicker.setPrefWidth(COMBO_BOX_WIDTH); datePicker.setPrefWidth(COMBO_BOX_WIDTH);
datePicker.setValue(LocalDate.now()); datePicker.setValue(LocalDate.now(ZoneId.systemDefault()));
var colorPicker = new ColorPicker(); var colorPicker = new ColorPicker();
colorPicker.setPrefWidth(COMBO_BOX_WIDTH); colorPicker.setPrefWidth(COMBO_BOX_WIDTH);

@ -22,6 +22,7 @@ import org.kordamp.ikonli.feather.Feather;
import org.kordamp.ikonli.javafx.FontIcon; import org.kordamp.ikonli.javafx.FontIcon;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.ZoneId;
import static atlantafx.sampler.page.SampleBlock.BLOCK_HGAP; import static atlantafx.sampler.page.SampleBlock.BLOCK_HGAP;
import static atlantafx.sampler.page.SampleBlock.BLOCK_VGAP; import static atlantafx.sampler.page.SampleBlock.BLOCK_VGAP;
@ -55,7 +56,7 @@ public class PopoverPage extends AbstractPage {
private SampleBlock datePickerSample() { private SampleBlock datePickerSample() {
var datePicker = new InlineDatePicker(); var datePicker = new InlineDatePicker();
datePicker.setValue(LocalDate.now()); datePicker.setValue(LocalDate.now(ZoneId.systemDefault()));
var popover = new Popover(datePicker); var popover = new Popover(datePicker);
popover.setHeaderAlwaysVisible(false); popover.setHeaderAlwaysVisible(false);

@ -4,6 +4,7 @@ package atlantafx.sampler.util;
import java.text.CharacterIterator; import java.text.CharacterIterator;
import java.text.StringCharacterIterator; import java.text.StringCharacterIterator;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.time.temporal.WeekFields; import java.time.temporal.WeekFields;
import java.util.Locale; import java.util.Locale;
@ -28,7 +29,7 @@ public final class HumanReadableFormat {
public static String date(LocalDateTime x) { public static String date(LocalDateTime x) {
Objects.requireNonNull(x); Objects.requireNonNull(x);
var now = LocalDateTime.now(); var now = LocalDateTime.now(ZoneId.systemDefault());
// not this year // not this year
if (x.getYear() != now.getYear()) { return DAY_MONTH_YEAR.format(x); } if (x.getYear() != now.getYear()) { return DAY_MONTH_YEAR.format(x); }