47 lines
1.4 KiB
Java
47 lines
1.4 KiB
Java
package controllers;
|
|
|
|
import java.time.Duration;
|
|
import java.time.LocalTime;
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.time.format.DateTimeParseException;
|
|
|
|
import javafx.scene.control.Alert;
|
|
import javafx.scene.control.Control;
|
|
|
|
public class FlightController {
|
|
private DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("HH:mm");
|
|
|
|
public double calculateFlightDuration(String abflugzeit, String ankunftszeit) throws DateTimeParseException {
|
|
LocalTime start = LocalTime.parse(abflugzeit, timeFormatter);
|
|
LocalTime end = LocalTime.parse(ankunftszeit, timeFormatter);
|
|
return (double) Duration.between(start, end).toMinutes() / 60;
|
|
}
|
|
|
|
public boolean isValidTime(String time) {
|
|
try {
|
|
LocalTime.parse(time, timeFormatter);
|
|
return true;
|
|
} catch (DateTimeParseException e) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public void setErrorStyle(Control field) {
|
|
field.setStyle("-fx-border-color: red;");
|
|
}
|
|
|
|
public void clearFieldStyles(Control... fields) {
|
|
for (Control field : fields) {
|
|
field.setStyle(null);
|
|
}
|
|
}
|
|
|
|
public void showAlert(String title, String message) {
|
|
Alert alert = new Alert(Alert.AlertType.ERROR);
|
|
alert.setTitle(title);
|
|
alert.setHeaderText(null);
|
|
alert.setContentText(message);
|
|
alert.showAndWait();
|
|
}
|
|
}
|