diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/scheduler/CronAdjuster.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/scheduler/CronAdjuster.java index 68ef5387e..13d37c922 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/scheduler/CronAdjuster.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/scheduler/CronAdjuster.java @@ -290,18 +290,33 @@ class CronAdjuster implements SchedulerTemporalAdjuster { if (range[0] == range[1]) { range[1] = max; } - return temporal -> { - final int n = temporal.get(chronoField); - return n >= range[0] && n <= range[1] && ((n - range[0]) % increment) == 0; - }; + if (range[0] > range[1]) { + return temporal -> { + final int n = temporal.get(chronoField); + return (n >= range[0] || n <= range[1]) && ((n - range[0]) % increment) == 0; + }; + } else { + return temporal -> { + final int n = temporal.get(chronoField); + return n >= range[0] && n <= range[1] && ((n - range[0]) % increment) == 0; + }; + } } // simple range/value check - return temporal -> { - final int n = temporal.get(chronoField); + if (range[0] > range[1]) { + return temporal -> { + final int n = temporal.get(chronoField); - return n >= range[0] && n <= range[1]; - }; + return n >= range[0] || n <= range[1]; + }; + } else { + return temporal -> { + final int n = temporal.get(chronoField); + + return n >= range[0] && n <= range[1]; + }; + } } /** @@ -428,14 +443,7 @@ class CronAdjuster implements SchedulerTemporalAdjuster { throw new IllegalArgumentException(String.format( "Value too high in range in cron expression '%s' in field '%s': value %s, minimum: %s", cronExpression, chronoField, r[1], max)); - } - if (r[0] > r[1]) { - throw new IllegalArgumentException(String.format( - "Minimum higher than maximum range in cron expression '%s' in field '%s': min: %s, max: %s", - cronExpression, chronoField, r[0], r[1])); - } - return r; } diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/scheduler/CronAdjusterMiscTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/scheduler/CronAdjusterMiscTest.java index bb4b9edd3..b79dcb6c2 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/scheduler/CronAdjusterMiscTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/scheduler/CronAdjusterMiscTest.java @@ -67,11 +67,6 @@ public class CronAdjusterMiscTest { new CronAdjuster("* * * X/10 * *"); } - @Test(expected = IllegalArgumentException.class) - public void testRangeWeekDay() { - new CronAdjuster("* * * * * FRI-1"); - } - @Test(expected = IllegalArgumentException.class) public void testRangeLeftSideError() { new CronAdjuster("X-3 * * * * *"); diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/scheduler/CronAdjusterTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/scheduler/CronAdjusterTest.java index 4bb9d466b..ad07a7fd4 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/scheduler/CronAdjusterTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/scheduler/CronAdjusterTest.java @@ -148,6 +148,11 @@ public class CronAdjusterTest { "2015-01-02T14:00" } }, { JAN_1ST_2015, "0 0 0 ? * SAT", new String[] { "2015-01-03T00:00" } }, { JAN_1ST_2015, "0 0 0 ? * SUN", new String[] { "2015-01-04T00:00" } }, + { JAN_1ST_2015, "0 0 0 ? * SUN-MON", + new String[] { "2015-01-04T00:00", "2015-01-05T00:00", "2015-01-11T00:00" } }, + { JAN_1ST_2000, "14-02/2 * * * * *", + new String[] { "2000-01-01T00:00:02", "2000-01-01T00:00:14", "2000-01-01T00:00:16", + "2000-01-01T00:00:18" } }, { JAN_1ST_2000, "10-14/2 * * * * *", new String[] { "2000-01-01T00:00:10", "2000-01-01T00:00:12", "2000-01-01T00:00:14", "2000-01-01T00:01:10" } },