mirror of
https://github.com/danieldemus/openhab-core.git
synced 2025-01-25 19:55:48 +01:00
[core] Fix for handling inverted cron ranges (#1519)
* Fix for handling inverted cron ranges This fix adds support for inverted cron ranged. For example SUN-WEN. It also works all ranges and also with additional increments. Closes #1516 Signed-off-by: Hilbrand Bouwkamp <hilbrand@h72.nl>
This commit is contained in:
parent
e37c28cfc9
commit
e84d01bafe
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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 * * * * *");
|
||||
|
@ -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" } },
|
||||
|
Loading…
Reference in New Issue
Block a user