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

View File

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

View File

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

View File

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

View File

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