mirror of
https://gitee.com/dromara/hutool.git
synced 2025-11-24 08:33:22 +08:00
Fix 4006
This commit is contained in:
@@ -18,6 +18,10 @@ public class BoolArrayMatcher implements PartMatcher {
|
|||||||
* 用户定义此字段的最小值
|
* 用户定义此字段的最小值
|
||||||
*/
|
*/
|
||||||
private final int minValue;
|
private final int minValue;
|
||||||
|
/**
|
||||||
|
* 用户定义此字段的最大值
|
||||||
|
*/
|
||||||
|
private final int maxValue;
|
||||||
private final boolean[] bValues;
|
private final boolean[] bValues;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -29,13 +33,15 @@ public class BoolArrayMatcher implements PartMatcher {
|
|||||||
Assert.isTrue(CollUtil.isNotEmpty(intValueList), "Values must be not empty!");
|
Assert.isTrue(CollUtil.isNotEmpty(intValueList), "Values must be not empty!");
|
||||||
bValues = new boolean[Collections.max(intValueList) + 1];
|
bValues = new boolean[Collections.max(intValueList) + 1];
|
||||||
int min = Integer.MAX_VALUE;
|
int min = Integer.MAX_VALUE;
|
||||||
|
int max = Integer.MIN_VALUE;
|
||||||
for (Integer value : intValueList) {
|
for (Integer value : intValueList) {
|
||||||
min = Math.min(min, value);
|
min = Math.min(min, value);
|
||||||
|
max = Math.max(max, value);
|
||||||
bValues[value] = true;
|
bValues[value] = true;
|
||||||
}
|
}
|
||||||
this.minValue = min;
|
this.minValue = min;
|
||||||
|
this.maxValue = max;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean match(Integer value) {
|
public boolean match(Integer value) {
|
||||||
if (null == value || value >= bValues.length) {
|
if (null == value || value >= bValues.length) {
|
||||||
@@ -69,6 +75,14 @@ public class BoolArrayMatcher implements PartMatcher {
|
|||||||
public int getMinValue() {
|
public int getMinValue() {
|
||||||
return this.minValue;
|
return this.minValue;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 获取表达式定义的最大值
|
||||||
|
*
|
||||||
|
* @return 最大值
|
||||||
|
*/
|
||||||
|
public int getMaxValue() {
|
||||||
|
return this.maxValue;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
|||||||
@@ -50,8 +50,19 @@ public class DayOfMonthMatcher extends BoolArrayMatcher {
|
|||||||
return value == Month.getLastDay(month - 1, isLeapYear);
|
return value == Month.getLastDay(month - 1, isLeapYear);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public boolean isLast() {
|
public boolean isLast() {
|
||||||
return match(31);
|
return match(31);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查value是否大于等于这个月的最大天
|
||||||
|
* @param value 被检查的值
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean isLastDay(int value) {
|
||||||
|
if(value>=getMaxValue()) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -192,7 +192,7 @@ public class PatternMatcher {
|
|||||||
// pr#1189
|
// pr#1189
|
||||||
if (i == Part.DAY_OF_MONTH.ordinal()
|
if (i == Part.DAY_OF_MONTH.ordinal()
|
||||||
&& matchers[i] instanceof DayOfMonthMatcher
|
&& matchers[i] instanceof DayOfMonthMatcher
|
||||||
&& ((DayOfMonthMatcher) matchers[i]).isLast()) {
|
&& ((DayOfMonthMatcher) matchers[i]).isLastDay(values[i])) {
|
||||||
int newMonth = newValues[Part.MONTH.ordinal()];
|
int newMonth = newValues[Part.MONTH.ordinal()];
|
||||||
int newYear = newValues[Part.YEAR.ordinal()];
|
int newYear = newValues[Part.YEAR.ordinal()];
|
||||||
nextValue = getLastDay(newMonth, newYear);
|
nextValue = getLastDay(newMonth, newYear);
|
||||||
@@ -226,7 +226,7 @@ public class PatternMatcher {
|
|||||||
continue;
|
continue;
|
||||||
} else if (i == Part.DAY_OF_MONTH.ordinal()
|
} else if (i == Part.DAY_OF_MONTH.ordinal()
|
||||||
&& matchers[i] instanceof DayOfMonthMatcher
|
&& matchers[i] instanceof DayOfMonthMatcher
|
||||||
&& ((DayOfMonthMatcher) matchers[i]).isLast()) {
|
&& ((DayOfMonthMatcher) matchers[i]).isLastDay(values[i])) {
|
||||||
int newMonth = newValues[Part.MONTH.ordinal()];
|
int newMonth = newValues[Part.MONTH.ordinal()];
|
||||||
int newYear = newValues[Part.YEAR.ordinal()];
|
int newYear = newValues[Part.YEAR.ordinal()];
|
||||||
nextValue = getLastDay(newMonth, newYear);
|
nextValue = getLastDay(newMonth, newYear);
|
||||||
@@ -259,7 +259,7 @@ public class PatternMatcher {
|
|||||||
part = Part.of(i);
|
part = Part.of(i);
|
||||||
if (part == Part.DAY_OF_MONTH
|
if (part == Part.DAY_OF_MONTH
|
||||||
&& get(part) instanceof DayOfMonthMatcher
|
&& get(part) instanceof DayOfMonthMatcher
|
||||||
&& ((DayOfMonthMatcher) get(part)).isLast()) {
|
&& ((DayOfMonthMatcher) get(part)).isLastDay(values[i])) {
|
||||||
int newMonth = values[Part.MONTH.ordinal()];
|
int newMonth = values[Part.MONTH.ordinal()];
|
||||||
int newYear = values[Part.YEAR.ordinal()];
|
int newYear = values[Part.YEAR.ordinal()];
|
||||||
values[i] = getLastDay(newMonth, newYear);
|
values[i] = getLastDay(newMonth, newYear);
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package cn.hutool.cron.pattern;
|
||||||
|
|
||||||
|
import cn.hutool.core.date.DateTime;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
public class Issue4006Test {
|
||||||
|
@Test
|
||||||
|
void testCron() {
|
||||||
|
// String cron = "0 0 0 */1 * ?";
|
||||||
|
String cron = "0 0 0 */1 * ? *";
|
||||||
|
DateTime judgeTime = DateTime.of(new Date());
|
||||||
|
CronPattern cronPattern = new CronPattern(cron);
|
||||||
|
|
||||||
|
System.out.println("cronPattern = " + cronPattern);
|
||||||
|
Date nextDate = CronPatternUtil.nextDateAfter(cronPattern, judgeTime, true);
|
||||||
|
System.out.println("nextDate = " + nextDate);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user