mirror of
https://gitee.com/dromara/hutool.git
synced 2025-09-18 17:48:17 +08:00
修复CronPatternUtil.nextDateAfter
计算下一个匹配表达式的日期时,计算错误问题(issue#4006@Github)
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
# 🚀Changelog
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
# 5.8.40(2025-08-20)
|
||||
# 5.8.40(2025-08-21)
|
||||
|
||||
### 🐣新特性
|
||||
* 【captcha】 `MathGenerator`四则运算方式支持不生成负数结果(pr#1363@Gitee)
|
||||
@@ -20,6 +20,7 @@
|
||||
* 【core 】 修复`TreeBuilder`append重复向idTreeMap中put问题(pr#3992@Github)
|
||||
* 【extra 】 修复`QLExpressEngine`allowClassSet无效问题(issue#3994@Github)
|
||||
* 【core 】 修复`StrBuilder`insert插入计算错误问题(issue#ICTSRZ@Gitee)
|
||||
* 【cron 】 修复`CronPatternUtil.nextDateAfter`计算下一个匹配表达式的日期时,计算错误问题(issue#4006@Github)
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
# 5.8.39(2025-06-20)
|
||||
|
@@ -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