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.LocalTime;
import java.time.ZoneId;
import java.time.chrono.HijrahChronology;
import java.time.format.DateTimeFormatter;
import java.util.Objects;
@ -42,23 +43,23 @@ import static javafx.scene.layout.GridPane.REMAINING;
public class DatePickerPage extends AbstractPage {
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 TIME_FORMATTER = DateTimeFormatter.ofPattern("HH:mm:ss");
private static final String DATE_FORMATTER_PROMPT = "yyyy-MM-dd";
private static final int INLINE_DATE_PICKER_COL = 0;
private static final int INLINE_DATE_PICKER_ROW = 4;
private static final CSSFragment NO_YEAR_MONTH_STYLE = new CSSFragment("""
.date-picker-popup >.month-year-pane {
visibility: hidden;
-fx-min-width: 0;
-fx-pref-width: 0;
-fx-max-width: 0;
-fx-min-height: 0;
-fx-pref-height: 0;
-fx-max-height: 0;
}
""");
.date-picker-popup >.month-year-pane {
visibility: hidden;
-fx-min-width: 0;
-fx-pref-width: 0;
-fx-max-width: 0;
-fx-min-height: 0;
-fx-pref-height: 0;
-fx-max-height: 0;
}
""");
@Override
public String getName() { return NAME; }
@ -227,21 +228,27 @@ public class DatePickerPage extends AbstractPage {
private static class Clock extends VBox {
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);
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("""
-fx-border-width: 0 0 0.5 0;
-fx-border-color: -color-border-default;"""
-fx-border-width: 0 0 0.5 0;
-fx-border-color: -color-border-default;"""
);
setSpacing(BLOCK_VGAP);
getChildren().setAll(clockLabel, dateLabel);
var t = new Timeline(new KeyFrame(
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.playFromStart();
@ -294,19 +301,19 @@ public class DatePickerPage extends AbstractPage {
private void updateStyle(String bgColorName, String fgColorName) {
style.set(new CSSFragment(String.format("""
.date-picker-popup {
-color-date-border: %s;
-color-date-month-year-bg: %s;
-color-date-month-year-fg: %s;
}
.date-picker-popup >.top-node {
-fx-background-color: %s;
-color-fg-default: %s;
-color-border-default: %s;
-fx-border-color: %s;
}""",
bgColorName, bgColorName, fgColorName,
bgColorName, fgColorName, fgColorName, fgColorName
.date-picker-popup {
-color-date-border: %s;
-color-date-month-year-bg: %s;
-color-date-month-year-fg: %s;
}
.date-picker-popup >.top-node {
-fx-background-color: %s;
-color-fg-default: %s;
-color-border-default: %s;
-fx-border-color: %s;
}""",
bgColorName, bgColorName, fgColorName,
bgColorName, fgColorName, fgColorName, fgColorName
)));
}
}

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

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

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