mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
fix bug
This commit is contained in:
parent
f9fb5eb127
commit
8506447419
@ -101,7 +101,7 @@ public enum Part {
|
||||
*/
|
||||
public int checkValue(final int value) throws CronException {
|
||||
Assert.checkBetween(value, min, max,
|
||||
() -> new CronException("Value {} out of range: [{} , {}]", value, min, max));
|
||||
() -> new CronException("{} value {} out of range: [{} , {}]", this.name(), value, min, max));
|
||||
return value;
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,6 @@ import org.dromara.hutool.core.text.split.SplitUtil;
|
||||
import org.dromara.hutool.cron.CronException;
|
||||
import org.dromara.hutool.cron.pattern.Part;
|
||||
import org.dromara.hutool.cron.pattern.matcher.*;
|
||||
import org.dromara.hutool.cron.pattern.matcher.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -213,13 +212,12 @@ public class PartParser {
|
||||
//在range模式下,如果步进不存在,表示步进为1
|
||||
step = 1;
|
||||
}
|
||||
if (v1 < v2) {// 正常范围,例如:2-5
|
||||
if (v1 <= v2) {// 正常范围,例如:2-5
|
||||
// 对于类似3-3这种形式,忽略step,即3-3/2与单值3一致
|
||||
NumberUtil.appendRange(v1, v2, step, results);
|
||||
} else if (v1 > v2) {// 逆向范围,反选模式,例如:5-2
|
||||
} else {// 逆向范围,反选模式,例如:5-2
|
||||
NumberUtil.appendRange(v1, part.getMax(), step, results);
|
||||
NumberUtil.appendRange(part.getMin(), v2, step, results);
|
||||
} else {// v1 == v2,此时与单值模式一致
|
||||
NumberUtil.appendRange(v1, part.getMax(), step, results);
|
||||
}
|
||||
} else {
|
||||
throw new CronException("Invalid syntax of field: [{}]", value);
|
||||
|
@ -0,0 +1,22 @@
|
||||
package org.dromara.hutool.cron.pattern;
|
||||
|
||||
import org.dromara.hutool.core.date.DateTime;
|
||||
import org.dromara.hutool.core.date.DateUtil;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class IssueI82CSHTest {
|
||||
|
||||
@SuppressWarnings("DataFlowIssue")
|
||||
@Test
|
||||
void test() {
|
||||
final DateTime begin = DateUtil.parse("2023-09-20");
|
||||
final DateTime end = DateUtil.parse("2025-09-20");
|
||||
final List<Date> dates = CronPatternUtil.matchedDates("0 0 1 3-3,9 *", begin, end, 20, false);
|
||||
//dates.forEach(Console::log);
|
||||
Assertions.assertEquals(4, dates.size());
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user