fixed time format

This commit is contained in:
Marc Beyer 2021-11-29 16:01:10 +01:00
parent 5a3c3845ed
commit 0296333733

View File

@ -1,5 +1,7 @@
package main;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.geometry.Pos;
@ -76,8 +78,7 @@ public class MainController {
stage.setResizable(false);
//stage.initStyle(StageStyle.UNDECORATED);
stage.showAndWait();
}
catch (IOException e){
} catch (IOException e) {
e.printStackTrace();
}
updateEvents();
@ -133,8 +134,12 @@ public class MainController {
Label nameLabel = new Label(event.getName());
vBox.getChildren().add(nameLabel);
Label timeLabel = new Label(event.getStart() + "-" + event.getEnd());
if (event.getStart() != null || event.getEnd() != null) {
String timeStr = (event.getStart() != null ? formatTime(event.getStart()) : "")
+ (event.getEnd() != null ? " - " + formatTime(event.getEnd()) : "");
Label timeLabel = new Label(timeStr);
vBox.getChildren().add(timeLabel);
}
Label typeLabel = new Label("Wer: " + event.getOwnerName());
vBox.getChildren().add(typeLabel);
@ -163,6 +168,14 @@ public class MainController {
}
}
private String formatTime(String time) {
String[] timeArr = time.split(":");
if (timeArr.length > 2) {
return timeArr[0] + ":" + timeArr[1];
}
return time;
}
private void setDates() {
DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("LLLL yyyy");
DateTimeFormatter dayFormatter = DateTimeFormatter.ofPattern("E dd.MM");
@ -171,7 +184,7 @@ public class MainController {
LocalDateTime now = LocalDateTime.now();
int dayOfWeek = Integer.parseInt(dayOfWeekFormatter.format(now));
weekStartDateTime = now.minusDays(weekOffset * 7L + dayOfWeek - 1);
weekStartDateTime = now.plusDays(weekOffset * 7L - dayOfWeek + 1);
for (int i = 0; i < 7; i++) {
dayLabel[i].setText(dayFormatter.format(weekStartDateTime.plusDays(i)));