ErrorProne: fix sampler/JavaTimeDefaultTimeZone
This commit is contained in:
parent
6920f98ca4
commit
dae2ab5a30
@ -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,23 +43,23 @@ 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";
|
||||||
private static final int INLINE_DATE_PICKER_COL = 0;
|
private static final int INLINE_DATE_PICKER_COL = 0;
|
||||||
private static final int INLINE_DATE_PICKER_ROW = 4;
|
private static final int INLINE_DATE_PICKER_ROW = 4;
|
||||||
private static final CSSFragment NO_YEAR_MONTH_STYLE = new CSSFragment("""
|
private static final CSSFragment NO_YEAR_MONTH_STYLE = new CSSFragment("""
|
||||||
.date-picker-popup >.month-year-pane {
|
.date-picker-popup >.month-year-pane {
|
||||||
visibility: hidden;
|
visibility: hidden;
|
||||||
-fx-min-width: 0;
|
-fx-min-width: 0;
|
||||||
-fx-pref-width: 0;
|
-fx-pref-width: 0;
|
||||||
-fx-max-width: 0;
|
-fx-max-width: 0;
|
||||||
-fx-min-height: 0;
|
-fx-min-height: 0;
|
||||||
-fx-pref-height: 0;
|
-fx-pref-height: 0;
|
||||||
-fx-max-height: 0;
|
-fx-max-height: 0;
|
||||||
}
|
}
|
||||||
""");
|
""");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() { return NAME; }
|
public String getName() { return NAME; }
|
||||||
@ -227,21 +228,27 @@ 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;
|
||||||
-fx-border-color: -color-border-default;"""
|
-fx-border-color: -color-border-default;"""
|
||||||
);
|
);
|
||||||
setSpacing(BLOCK_VGAP);
|
setSpacing(BLOCK_VGAP);
|
||||||
getChildren().setAll(clockLabel, dateLabel);
|
getChildren().setAll(clockLabel, dateLabel);
|
||||||
|
|
||||||
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();
|
||||||
@ -294,19 +301,19 @@ public class DatePickerPage extends AbstractPage {
|
|||||||
|
|
||||||
private void updateStyle(String bgColorName, String fgColorName) {
|
private void updateStyle(String bgColorName, String fgColorName) {
|
||||||
style.set(new CSSFragment(String.format("""
|
style.set(new CSSFragment(String.format("""
|
||||||
.date-picker-popup {
|
.date-picker-popup {
|
||||||
-color-date-border: %s;
|
-color-date-border: %s;
|
||||||
-color-date-month-year-bg: %s;
|
-color-date-month-year-bg: %s;
|
||||||
-color-date-month-year-fg: %s;
|
-color-date-month-year-fg: %s;
|
||||||
}
|
}
|
||||||
.date-picker-popup >.top-node {
|
.date-picker-popup >.top-node {
|
||||||
-fx-background-color: %s;
|
-fx-background-color: %s;
|
||||||
-color-fg-default: %s;
|
-color-fg-default: %s;
|
||||||
-color-border-default: %s;
|
-color-border-default: %s;
|
||||||
-fx-border-color: %s;
|
-fx-border-color: %s;
|
||||||
}""",
|
}""",
|
||||||
bgColorName, bgColorName, fgColorName,
|
bgColorName, bgColorName, fgColorName,
|
||||||
bgColorName, fgColorName, fgColorName, fgColorName
|
bgColorName, fgColorName, fgColorName, fgColorName
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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); }
|
||||||
|
Loading…
Reference in New Issue
Block a user