mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
fix code
This commit is contained in:
parent
d890d60b14
commit
2722a971af
@ -158,6 +158,11 @@ public class PatternMatcher {
|
|||||||
// 新值,-1表示标识为回退
|
// 新值,-1表示标识为回退
|
||||||
int nextValue = 0;
|
int nextValue = 0;
|
||||||
while (i >= 0) {
|
while (i >= 0) {
|
||||||
|
if(i == Part.DAY_OF_WEEK.ordinal()){
|
||||||
|
// 周不参与计算
|
||||||
|
i--;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
nextValue = matchers[i].nextAfter(values[i]);
|
nextValue = matchers[i].nextAfter(values[i]);
|
||||||
if (nextValue > values[i]) {
|
if (nextValue > values[i]) {
|
||||||
// 此部分正常获取新值,结束循环,后续的部分置最小值
|
// 此部分正常获取新值,结束循环,后续的部分置最小值
|
||||||
@ -177,6 +182,11 @@ public class PatternMatcher {
|
|||||||
// 值产生回退,向上查找变更值
|
// 值产生回退,向上查找变更值
|
||||||
if (-1 == nextValue) {
|
if (-1 == nextValue) {
|
||||||
while (i <= Part.YEAR.ordinal()) {
|
while (i <= Part.YEAR.ordinal()) {
|
||||||
|
if(i == Part.DAY_OF_WEEK.ordinal()){
|
||||||
|
// 周不参与计算
|
||||||
|
i++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
nextValue = matchers[i].nextAfter(values[i] + 1);
|
nextValue = matchers[i].nextAfter(values[i] + 1);
|
||||||
if (nextValue > values[i]) {
|
if (nextValue > values[i]) {
|
||||||
newValues[i] = nextValue;
|
newValues[i] = nextValue;
|
||||||
@ -250,6 +260,7 @@ public class PatternMatcher {
|
|||||||
}
|
}
|
||||||
//noinspection MagicConstant
|
//noinspection MagicConstant
|
||||||
calendar.set(part.getCalendarField(), value);
|
calendar.set(part.getCalendarField(), value);
|
||||||
|
//Console.log("Set [{}] as [{}]", part, value);
|
||||||
return calendar;
|
return calendar;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ package cn.hutool.cron.pattern;
|
|||||||
import cn.hutool.core.date.DateField;
|
import cn.hutool.core.date.DateField;
|
||||||
import cn.hutool.core.date.DateTime;
|
import cn.hutool.core.date.DateTime;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.core.lang.Console;
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
@ -96,6 +95,5 @@ public class CronPatternNextMatchTest {
|
|||||||
final DateTime time = DateUtil.parse("2022-04-01");
|
final DateTime time = DateUtil.parse("2022-04-01");
|
||||||
assert time != null;
|
assert time != null;
|
||||||
final Calendar calendar = pattern.nextMatchAfter(time.toCalendar());
|
final Calendar calendar = pattern.nextMatchAfter(time.toCalendar());
|
||||||
Console.log(DateUtil.date(calendar));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user