|
|
@@ -12,7 +12,11 @@ import java.net.URISyntaxException;
|
|
|
import java.time.Instant;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.ZoneOffset;
|
|
|
+import java.time.temporal.ChronoUnit;
|
|
|
import java.util.TimeZone;
|
|
|
+import java.util.function.Supplier;
|
|
|
+
|
|
|
+import static java.time.ZoneId.systemDefault;
|
|
|
|
|
|
public class SenslogConfig {
|
|
|
|
|
|
@@ -36,7 +40,8 @@ public class SenslogConfig {
|
|
|
}
|
|
|
|
|
|
private final TimeZone timeZone;
|
|
|
- private final LocalDateTime startDate;
|
|
|
+ private LocalDateTime startDate;
|
|
|
+ private final Supplier<LocalDateTime> startDateSupplier;
|
|
|
private final String user;
|
|
|
private final Integer interval;
|
|
|
private final AllowedStation allowedStation;
|
|
|
@@ -49,19 +54,25 @@ public class SenslogConfig {
|
|
|
this.timeZone = TimeZone.getTimeZone(defaultConfig.getStringProperty("timeZone"));
|
|
|
String startDate = defaultConfig.getStringProperty("startDate");
|
|
|
|
|
|
+ boolean isDelay = defaultConfig.containsProperty("delayStartDate");
|
|
|
LocalDateTime tempStartDate = null;
|
|
|
if (startDate.equalsIgnoreCase("now")) {
|
|
|
- tempStartDate = LocalDateTime.ofInstant(Instant.now(), timeZone.toZoneId());
|
|
|
+ if (isDelay) {
|
|
|
+ int delay = defaultConfig.getIntegerProperty("delayStartDate");
|
|
|
+ startDateSupplier = () -> LocalDateTime.ofInstant(Instant.now(), timeZone.toZoneId()).minusMinutes(delay);
|
|
|
+ } else {
|
|
|
+ startDateSupplier = () -> LocalDateTime.ofInstant(Instant.now(), timeZone.toZoneId());
|
|
|
+ }
|
|
|
} else {
|
|
|
LocalDateTime configSystemTime = defaultConfig.getLocalDateTimeProperty("startDate");
|
|
|
- tempStartDate = LocalDateTime.ofInstant(configSystemTime.atZone(ZoneOffset.systemDefault()).toInstant(), timeZone.toZoneId());
|
|
|
- }
|
|
|
-
|
|
|
- if (defaultConfig.containsProperty("delayStartDate")) {
|
|
|
- tempStartDate = tempStartDate.minusMinutes(defaultConfig.getIntegerProperty("delayStartDate"));
|
|
|
+ if (isDelay) {
|
|
|
+ int delay = defaultConfig.getIntegerProperty("delayStartDate");
|
|
|
+ startDateSupplier = () -> LocalDateTime.ofInstant(configSystemTime.atZone(systemDefault()).toInstant(), timeZone.toZoneId()).minusMinutes(delay);
|
|
|
+ } else {
|
|
|
+ startDateSupplier = () -> LocalDateTime.ofInstant(configSystemTime.atZone(systemDefault()).toInstant(), timeZone.toZoneId());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- this.startDate = tempStartDate;
|
|
|
this.user = defaultConfig.getStringProperty("user");
|
|
|
this.interval = defaultConfig.getIntegerProperty("interval");
|
|
|
this.allowedStation = new AllowedStation(defaultConfig.getPropertyConfig("allowedStation"));
|
|
|
@@ -78,6 +89,9 @@ public class SenslogConfig {
|
|
|
}
|
|
|
|
|
|
public LocalDateTime getStartDate() {
|
|
|
+ if (startDate == null) {
|
|
|
+ startDate = startDateSupplier.get();
|
|
|
+ }
|
|
|
return startDate;
|
|
|
}
|
|
|
|