File tree Expand file tree Collapse file tree 3 files changed +30
-4
lines changed
main/java/de/doubleslash/keeptime
test/java/de/doubleslash/keeptime/common Expand file tree Collapse file tree 3 files changed +30
-4
lines changed Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ public class DateFormatter {
3131 private static DateTimeFormatter dayDateFormatter = DateTimeFormatter .ofPattern ("eeee dd.MM.yyyy" );
3232 private static DateTimeFormatter timeFormatter = DateTimeFormatter .ofPattern ("HH:mm:ss" );
3333
34- private static Locale systemLocale = Locale .GERMAN ;
34+ private static Locale systemLocale = Locale .getDefault () ;
3535
3636 private DateFormatter () {
3737 throw new IllegalStateException ("Utility class: DateFormatter" );
Original file line number Diff line number Diff line change @@ -124,7 +124,9 @@ public class ExternalProjectsSyncController {
124124 private final Color colorLoadingSuccess = Color .valueOf ("#74a317" );
125125 private final Color colorLoadingFailure = Color .valueOf ("#c63329" );
126126
127- private final LocalTimeStringConverter localTimeStringConverter = new LocalTimeStringConverter (FormatStyle .MEDIUM );
127+ private final LocalTimeStringConverter localTimeStringConverter = new LocalTimeStringConverter (
128+ FormatStyle .MEDIUM ,
129+ DateFormatter .getSystemLocale ());
128130 private ObservableList <TableRow > items ;
129131
130132 private LocalDate currentReportDate ;
@@ -579,8 +581,10 @@ private void showErrorDialog(List<String> errorMessages) {
579581 }
580582
581583 private void setUpTimeSpinner (final Spinner <LocalTime > spinner ) {
584+ final LocalTimeStringConverter stringConverter = new LocalTimeStringConverter (
585+ FormatStyle .MEDIUM ,
586+ DateFormatter .getSystemLocale ());
582587 spinner .focusedProperty ().addListener (e -> {
583- final LocalTimeStringConverter stringConverter = new LocalTimeStringConverter (FormatStyle .MEDIUM );
584588 final StringProperty text = spinner .getEditor ().textProperty ();
585589 try {
586590 stringConverter .fromString (text .get ());
@@ -621,7 +625,7 @@ public void increment(final int steps) {
621625
622626 });
623627
624- spinner .getValueFactory ().setConverter (new LocalTimeStringConverter ( FormatStyle . MEDIUM ) );
628+ spinner .getValueFactory ().setConverter (stringConverter );
625629 }
626630
627631 public static LocalTime decrementToLastFullQuarter (LocalTime time ) {
Original file line number Diff line number Diff line change 1818
1919import static org .hamcrest .MatcherAssert .assertThat ;
2020
21+ import java .time .LocalDate ;
2122import java .time .LocalDateTime ;
23+ import java .util .Locale ;
2224
25+ import javafx .scene .control .DatePicker ;
2326import org .hamcrest .Matchers ;
2427import org .junit .jupiter .api .Disabled ;
2528import org .junit .jupiter .api .Test ;
2629
30+ import static org .junit .jupiter .api .Assertions .assertTrue ;
31+
2732@ Disabled
2833class DateFormatterTest {
2934
@@ -38,4 +43,21 @@ void zeroSecondsBetweenTest() {
3843 final long secondsBewtweenSwitched = DateFormatter .getSecondsBewtween (endDate , startDate );
3944 assertThat (secondsBewtweenSwitched , Matchers .is (0l )); // why??
4045 }
46+
47+ @ Test
48+ void applySystemLocaleShouldSetDatePickerLocale () {
49+ // GIVEN
50+ Locale .setDefault (Locale .ENGLISH );
51+ DateFormatter .setSystemLocale (Locale .GERMAN );
52+ DatePicker datePicker = new DatePicker ();
53+ LocalDate date = LocalDate .of (2024 , 6 , 3 );
54+
55+ // WHEN
56+ DateFormatter .applySystemLocaleOnDate (datePicker );
57+ datePicker .setValue (date );
58+
59+ // THEN
60+ String shown = datePicker .getEditor ().getText ();
61+ assertTrue (shown .contains ("Montag" ) || shown .contains ("06.2024" ) || shown .contains ("06" ));
62+ }
4163}
You can’t perform that action at this time.
0 commit comments