Compare commits

..

No commits in common. "645b1f2414cd036f4db0f767b27e6694712ebcd1" and "4cd70e02c71b2d41127262b8bffd3ceaf7922358" have entirely different histories.

5 changed files with 45 additions and 51 deletions

View File

@ -11,8 +11,6 @@ import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -124,12 +122,10 @@ public class LinuxScheduler {
* minute (059) * minute (059)
*/ */
public static String cronExpression(StationSettings settings) throws CronExpressionException { public static String cronExpression(StationSettings settings) throws CronExpressionException {
LocalDateTime scheduleDateTime = settings.getScheduleStart().withZoneSameInstant(ZoneId.systemDefault()).toLocalDateTime(); String minute = Integer.toString(settings.getScheduleStartTime().getMinute());
String hour = Integer.toString(settings.getScheduleStartTime().getHour());
String minute = Integer.toString(scheduleDateTime.getMinute()); String dayOfMonth = Integer.toString(settings.getScheduleStartDate().getDayOfMonth());
String hour = Integer.toString(scheduleDateTime.getHour()); String dayOfWeek = Integer.toString(settings.getScheduleStartDate().getDayOfMonth());
String dayOfMonth = Integer.toString(scheduleDateTime.getDayOfMonth());
String dayOfWeek = Integer.toString(scheduleDateTime.getDayOfMonth());
String scheduleString = ""; String scheduleString = "";
switch(settings.getMessagePeriod()) { switch(settings.getMessagePeriod()) {

View File

@ -112,9 +112,6 @@ public class StationSelectionController {
@FXML @FXML
private void handleRemoveButtonPress(ActionEvent event) { private void handleRemoveButtonPress(ActionEvent event) {
int selectedIndex = stationListView.getSelectionModel().getSelectedIndex(); int selectedIndex = stationListView.getSelectionModel().getSelectedIndex();
if (selectedIndex < 0) {
return;
}
StationSettings station = stationList.get(selectedIndex); StationSettings station = stationList.get(selectedIndex);
String stationName = station.toString(); String stationName = station.toString();

View File

@ -12,8 +12,6 @@ import java.nio.file.SimpleFileVisitor;
import java.security.SecureRandom; import java.security.SecureRandom;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.ZonedDateTime;
import java.time.ZoneId;
import java.time.LocalTime; import java.time.LocalTime;
import java.time.Period; import java.time.Period;
import java.util.ArrayList; import java.util.ArrayList;
@ -34,7 +32,8 @@ public class StationSettings {
private String name; private String name;
private String password; private String password;
private ArrayList<String> prefixes; private ArrayList<String> prefixes;
private ZonedDateTime scheduleStart; private LocalDate scheduleStartDate;
private LocalTime scheduleStartTime;
private String username; private String username;
public enum MessageMethod { public enum MessageMethod {
@ -55,7 +54,8 @@ public class StationSettings {
messageLength = 100; messageLength = 100;
messageMethod = MessageMethod.SFTP; messageMethod = MessageMethod.SFTP;
messagePeriod = MessagePeriod.DAILY; messagePeriod = MessagePeriod.DAILY;
scheduleStart = ZonedDateTime.now(); scheduleStartDate = LocalDate.now();
scheduleStartTime = LocalTime.now();
} }
public StationSettings(String newName) { public StationSettings(String newName) {
@ -65,7 +65,8 @@ public class StationSettings {
messageLength = 100; messageLength = 100;
messageMethod = MessageMethod.SFTP; messageMethod = MessageMethod.SFTP;
messagePeriod = MessagePeriod.DAILY; messagePeriod = MessagePeriod.DAILY;
scheduleStart = ZonedDateTime.now(); scheduleStartDate = LocalDate.now();
scheduleStartTime = LocalTime.now();
} }
public static void deleteStationData(String stationName) throws IOException { public static void deleteStationData(String stationName) throws IOException {
@ -183,43 +184,42 @@ public class StationSettings {
} }
public LocalDateTime nextSendTime() throws StationSettingsException { public LocalDateTime nextSendTime() throws StationSettingsException {
LocalDate startDate = scheduleStart.withZoneSameInstant(ZoneId.systemDefault()).toLocalDate(); Period sinceScheduleStart = Period.between(scheduleStartDate , LocalDate.now());
LocalTime startTime = scheduleStart.withZoneSameInstant(ZoneId.systemDefault()).toLocalTime();
Period sinceScheduleStart = Period.between(startDate, LocalDate.now());
// If this period's time has not yet passed, then show that time. // If this period's time has not yet passed, then show that time.
// Otherwise, show the next period's time. // Otherwise, show the next period's time.
switch (messagePeriod) { switch (messagePeriod) {
case DAILY: case DAILY:
if (LocalTime.now().isBefore(startTime)) { if (LocalTime.now().isBefore(scheduleStartTime)) {
return LocalDate.now().atTime(startTime); return LocalDate.now().atTime(scheduleStartTime);
} else { } else {
return LocalDate.now().plusDays(1).atTime(startTime); return LocalDate.now().plusDays(1).atTime(scheduleStartTime);
} }
case WEEKLY: case WEEKLY:
int weekdayDifference = startDate.getDayOfWeek().getValue() - LocalDate.now().getDayOfWeek().getValue(); int weekdayDifference = scheduleStartDate.getDayOfWeek().getValue() - LocalDate.now().getDayOfWeek().getValue();
System.out.println("weekdayDifference: " + weekdayDifference);
if (weekdayDifference > 0) { if (weekdayDifference > 0) {
return LocalDate.now().plusDays(weekdayDifference).atTime(startTime); return LocalDate.now().plusDays(weekdayDifference).atTime(scheduleStartTime);
} else if (weekdayDifference == 0){ } else if (weekdayDifference == 0){
if (LocalTime.now().isBefore(startTime)) { if (LocalTime.now().isBefore(scheduleStartTime)) {
return LocalDate.now().atTime(startTime); return LocalDate.now().atTime(scheduleStartTime);
} else { } else {
return LocalDate.now().plusWeeks(1).atTime(startTime); return LocalDate.now().plusWeeks(1).atTime(scheduleStartTime);
} }
} else { } else {
return LocalDate.now().plusDays(7 + weekdayDifference).atTime(startTime); return LocalDate.now().plusDays(7 + weekdayDifference).atTime(scheduleStartTime);
} }
case MONTHLY: case MONTHLY:
int monthdayDifference = startDate.getDayOfMonth() - LocalDate.now().getDayOfMonth(); int monthdayDifference = scheduleStartDate.getDayOfMonth() - LocalDate.now().getDayOfMonth();
if (monthdayDifference > 0) { if (monthdayDifference > 0) {
return LocalDate.now().plusDays(monthdayDifference).atTime(startTime); return LocalDate.now().plusDays(monthdayDifference).atTime(scheduleStartTime);
} else if (monthdayDifference == 0) { } else if (monthdayDifference == 0) {
if (LocalTime.now().isBefore(startTime)) { if (LocalTime.now().isBefore(scheduleStartTime)) {
return LocalDate.now().atTime(startTime); return LocalDate.now().atTime(scheduleStartTime);
} else { } else {
return LocalDate.now().plusMonths(1).atTime(startTime); return LocalDate.now().plusMonths(1).atTime(scheduleStartTime);
} }
} else { } else {
return LocalDate.now().plusMonths(1).plusDays(monthdayDifference).atTime(startTime); return LocalDate.now().plusMonths(1).plusDays(monthdayDifference).atTime(scheduleStartTime);
} }
default: default:
throw new StationSettingsException("Invalid period value: " + messagePeriod); throw new StationSettingsException("Invalid period value: " + messagePeriod);
@ -305,12 +305,20 @@ public class StationSettings {
return prefixes; return prefixes;
} }
public ZonedDateTime getScheduleStart() { public LocalDate getScheduleStartDate() {
return scheduleStart; return scheduleStartDate;
} }
public void setScheduleStart(ZonedDateTime newScheduleStart) { public void setScheduleStartDate(LocalDate newScheduleStartDate) {
scheduleStart = newScheduleStart; scheduleStartDate = newScheduleStartDate;
}
public LocalTime getScheduleStartTime() {
return scheduleStartTime;
}
public void setScheduleStartTime(LocalTime newScheduleStartTime) {
scheduleStartTime = newScheduleStartTime;
} }
public String getUsername() { public String getUsername() {

View File

@ -15,9 +15,6 @@ import java.nio.file.Path;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalTime; import java.time.LocalTime;
import java.time.ZonedDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
@ -436,6 +433,7 @@ public class StationSettingsController {
settings.setPassword(password.get()); settings.setPassword(password.get());
settings.getPrefixes().clear(); settings.getPrefixes().clear();
settings.getPrefixes().addAll(prefixListView.getItems()); settings.getPrefixes().addAll(prefixListView.getItems());
settings.setScheduleStartDate(scheduleStartDatePicker.getValue());
settings.setUsername(username.get()); settings.setUsername(username.get());
try { try {
@ -449,9 +447,7 @@ public class StationSettingsController {
try { try {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm:ss"); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm:ss");
LocalTime startTime = LocalTime.parse(scheduleStartTimeField.getText(), formatter); LocalTime startTime = LocalTime.parse(scheduleStartTimeField.getText(), formatter);
ZonedDateTime scheduleStart = ZonedDateTime.of(scheduleStartDatePicker.getValue(), startTime, ZoneId.systemDefault()); settings.setScheduleStartTime(startTime);
settings.setScheduleStart(scheduleStart.withZoneSameInstant(ZoneOffset.UTC));
} catch (Exception ex) { } catch (Exception ex) {
logger.log(Level.SEVERE, "Error parsing schedule start time", ex); logger.log(Level.SEVERE, "Error parsing schedule start time", ex);
} }
@ -561,9 +557,9 @@ public class StationSettingsController {
password.set(settings.getPassword()); password.set(settings.getPassword());
System.out.println(settings.getPrefixes()); System.out.println(settings.getPrefixes());
prefixListView.getItems().addAll(settings.getPrefixes()); prefixListView.getItems().addAll(settings.getPrefixes());
scheduleStartDate.set(settings.getScheduleStart().withZoneSameInstant(ZoneId.systemDefault()).toLocalDate()); scheduleStartDate.set(settings.getScheduleStartDate());
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm:ss"); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm:ss");
LocalTime startTime = settings.getScheduleStart().withZoneSameInstant(ZoneId.systemDefault()).toLocalTime(); LocalTime startTime = settings.getScheduleStartTime();
if (startTime == null) { if (startTime == null) {
startTime = LocalTime.now(); startTime = LocalTime.now();
} }

View File

@ -16,9 +16,7 @@ import java.util.concurrent.TimeUnit;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.ZoneId;
import javafx.util.Pair; import javafx.util.Pair;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory;
@ -46,7 +44,7 @@ public class WindowsScheduler {
rootElement.setAttribute("xmlns", "http://schemas.microsoft.com/windows/2004/02/mit/task"); rootElement.setAttribute("xmlns", "http://schemas.microsoft.com/windows/2004/02/mit/task");
doc.appendChild(rootElement); doc.appendChild(rootElement);
LocalDateTime scheduleDateTime = station.getScheduleStart().withZoneSameInstant(ZoneId.systemDefault()).toLocalDateTime(); LocalDateTime scheduleDateTime = station.getScheduleStartDate().atTime(station.getScheduleStartTime());
DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss"); DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");
// RegistrationInfo element // RegistrationInfo element
@ -109,8 +107,7 @@ public class WindowsScheduler {
Element daysOfMonth = doc.createElement("DaysOfMonth"); Element daysOfMonth = doc.createElement("DaysOfMonth");
scheduleByMonth.appendChild(daysOfMonth); scheduleByMonth.appendChild(daysOfMonth);
Element day = doc.createElement("Day"); Element day = doc.createElement("Day");
LocalDate startDate = station.getScheduleStart().withZoneSameInstant(ZoneId.systemDefault()).toLocalDate(); day.appendChild(doc.createTextNode(String.valueOf(station.getScheduleStartDate().getDayOfMonth())));
day.appendChild(doc.createTextNode(String.valueOf(startDate.getDayOfMonth())));
daysOfMonth.appendChild(day); daysOfMonth.appendChild(day);
Element months = doc.createElement("Months"); Element months = doc.createElement("Months");