mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
修复Cron表达式range解析错误问题
This commit is contained in:
parent
58be7dcd97
commit
90646bc45d
@ -2,11 +2,12 @@
|
||||
# 🚀Changelog
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
# 5.8.23(2023-09-13)
|
||||
# 5.8.23(2023-09-20)
|
||||
|
||||
### 🐣新特性
|
||||
|
||||
### 🐞Bug修复
|
||||
* 【cron 】 修复Cron表达式range解析错误问题(issue#I82CSH@Gitee)
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
# 5.8.22(2023-09-13)
|
||||
|
@ -89,7 +89,7 @@ public enum Part {
|
||||
*/
|
||||
public int checkValue(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;
|
||||
}
|
||||
|
||||
|
@ -7,11 +7,7 @@ import cn.hutool.core.util.NumberUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.cron.CronException;
|
||||
import cn.hutool.cron.pattern.Part;
|
||||
import cn.hutool.cron.pattern.matcher.AlwaysTrueMatcher;
|
||||
import cn.hutool.cron.pattern.matcher.BoolArrayMatcher;
|
||||
import cn.hutool.cron.pattern.matcher.DayOfMonthMatcher;
|
||||
import cn.hutool.cron.pattern.matcher.PartMatcher;
|
||||
import cn.hutool.cron.pattern.matcher.YearValueMatcher;
|
||||
import cn.hutool.cron.pattern.matcher.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -203,13 +199,11 @@ public class PartParser {
|
||||
//在range模式下,如果步进不存在,表示步进为1
|
||||
step = 1;
|
||||
}
|
||||
if (v1 < v2) {// 正常范围,例如:2-5
|
||||
if (v1 <= v2) {// 正常范围,例如:2-5,3-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,21 @@
|
||||
package cn.hutool.cron.pattern;
|
||||
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class IssueI82CSHTest {
|
||||
|
||||
@Test
|
||||
public 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);
|
||||
Assert.assertEquals(4, dates.size());
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user