mirror of
https://gitee.com/dromara/hutool.git
synced 2025-11-24 08:33:22 +08:00
修复CronPatternUtil.nextDateAfter计算下一个匹配表达式的日期时,计算错误问题(issue#4006@Github)
This commit is contained in:
@@ -192,7 +192,7 @@ public class PatternMatcher {
|
||||
// pr#1189
|
||||
if (i == Part.DAY_OF_MONTH.ordinal()
|
||||
&& matchers[i] instanceof DayOfMonthMatcher
|
||||
&& ((DayOfMonthMatcher) matchers[i]).isLastDay(values[i],values[i+1],isLeapYear(values[Part.YEAR.ordinal()]))) {
|
||||
&& ((DayOfMonthMatcher) matchers[i]).isLastDay(values[i],values[i+1],DateUtil.isLeapYear(values[Part.YEAR.ordinal()]))) {
|
||||
int newMonth = newValues[Part.MONTH.ordinal()];
|
||||
int newYear = newValues[Part.YEAR.ordinal()];
|
||||
nextValue = getLastDay(newMonth, newYear);
|
||||
@@ -226,7 +226,7 @@ public class PatternMatcher {
|
||||
continue;
|
||||
} else if (i == Part.DAY_OF_MONTH.ordinal()
|
||||
&& matchers[i] instanceof DayOfMonthMatcher
|
||||
&& ((DayOfMonthMatcher) matchers[i]).isLastDay(values[i],values[i+1],isLeapYear(values[Part.YEAR.ordinal()]))) {
|
||||
&& ((DayOfMonthMatcher) matchers[i]).isLastDay(values[i],values[i+1],DateUtil.isLeapYear(values[Part.YEAR.ordinal()]))) {
|
||||
int newMonth = newValues[Part.MONTH.ordinal()];
|
||||
int newYear = newValues[Part.YEAR.ordinal()];
|
||||
nextValue = getLastDay(newMonth, newYear);
|
||||
@@ -247,14 +247,6 @@ public class PatternMatcher {
|
||||
return newValues;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断年份是否是闰年
|
||||
* @param year
|
||||
* @return 返回boolean表示是否是闰年
|
||||
*/
|
||||
private static boolean isLeapYear(int year) {
|
||||
return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
|
||||
}
|
||||
/**
|
||||
* 设置从{@link Part#SECOND}到指定部分,全部设置为最小值
|
||||
*
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package cn.hutool.cron.pattern;
|
||||
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Date;
|
||||
@@ -13,8 +14,8 @@ public class Issue4006Test {
|
||||
DateTime judgeTime = DateTime.of(new Date());
|
||||
CronPattern cronPattern = new CronPattern(cron);
|
||||
|
||||
System.out.println("cronPattern = " + cronPattern);
|
||||
Console.log("cronPattern = " + cronPattern);
|
||||
Date nextDate = CronPatternUtil.nextDateAfter(cronPattern, judgeTime, true);
|
||||
System.out.println("nextDate = " + nextDate);
|
||||
Console.log("nextDate = " + nextDate);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user