From f2cc6a288e1b21df731a61b93c4d1b089fd82861 Mon Sep 17 00:00:00 2001 From: Thomas Kurz Date: Thu, 30 Nov 2023 13:27:59 +0100 Subject: [PATCH 1/2] HOTFIX prevent NPE for relative dates without hours and minutes set --- .../io/redlink/more/data/model/scheduler/RelativeDate.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/redlink/more/data/model/scheduler/RelativeDate.java b/src/main/java/io/redlink/more/data/model/scheduler/RelativeDate.java index 830ba69..c2d2be7 100644 --- a/src/main/java/io/redlink/more/data/model/scheduler/RelativeDate.java +++ b/src/main/java/io/redlink/more/data/model/scheduler/RelativeDate.java @@ -23,8 +23,11 @@ public int getMinutes() { private int getTimeGroup(int i) { Matcher m = CLOCK.matcher(time); - m.find(); - return Integer.parseInt(m.group(i)); + if(m.find()) { + return Integer.parseInt(m.group(i)); + } else { + return 0; + } } public Duration getOffset() { From 308fdaaf544e05b6af99b504188d349f6298a295 Mon Sep 17 00:00:00 2001 From: Thomas Kurz Date: Thu, 30 Nov 2023 14:04:39 +0100 Subject: [PATCH 2/2] HOTFIX prevent NPE for relative dates and correct md for instant creation --- .../io/redlink/more/data/model/scheduler/RelativeDate.java | 3 +++ .../java/io/redlink/more/data/schedule/SchedulerUtils.java | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/redlink/more/data/model/scheduler/RelativeDate.java b/src/main/java/io/redlink/more/data/model/scheduler/RelativeDate.java index c2d2be7..a83a502 100644 --- a/src/main/java/io/redlink/more/data/model/scheduler/RelativeDate.java +++ b/src/main/java/io/redlink/more/data/model/scheduler/RelativeDate.java @@ -22,6 +22,9 @@ public int getMinutes() { } private int getTimeGroup(int i) { + if(time == null) { + return 0; + } Matcher m = CLOCK.matcher(time); if(m.find()) { return Integer.parseInt(m.group(i)); diff --git a/src/main/java/io/redlink/more/data/schedule/SchedulerUtils.java b/src/main/java/io/redlink/more/data/schedule/SchedulerUtils.java index 00e4870..b0ad64e 100644 --- a/src/main/java/io/redlink/more/data/schedule/SchedulerUtils.java +++ b/src/main/java/io/redlink/more/data/schedule/SchedulerUtils.java @@ -64,7 +64,10 @@ private static Instant shiftStartIfNecessary(Instant start) { private static Instant toInstant(RelativeDate date, Instant start) { return ZonedDateTime.ofInstant(start.plus(date.getOffset().getValue() - 1L, date.getOffset().getUnit().toTemporalUnit()), ZoneId.systemDefault()) .withHour(date.getHours()) - .withMinute(date.getMinutes()).toInstant(); + .withMinute(date.getMinutes()) + .withSecond(0) + .withNano(0) + .toInstant(); } public static List> parseToObservationSchedulesForEvent(Event event, Instant start, Instant end) {