mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
fix cocde
This commit is contained in:
parent
64fdf75fc6
commit
1e5d8badfd
@ -125,15 +125,8 @@ public class CronPattern {
|
|||||||
* @return 如果匹配返回 {@code true}, 否则返回 {@code false}
|
* @return 如果匹配返回 {@code true}, 否则返回 {@code false}
|
||||||
*/
|
*/
|
||||||
public boolean match(Calendar calendar, boolean isMatchSecond) {
|
public boolean match(Calendar calendar, boolean isMatchSecond) {
|
||||||
final int second = isMatchSecond ? calendar.get(Calendar.SECOND) : -1;
|
final int[] fields = getFields(calendar, isMatchSecond);
|
||||||
final int minute = calendar.get(Calendar.MINUTE);
|
return match(fields[0], fields[1], fields[2], fields[3], fields[4], fields[5], fields[6]);
|
||||||
final int hour = calendar.get(Calendar.HOUR_OF_DAY);
|
|
||||||
final int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
|
|
||||||
final int month = calendar.get(Calendar.MONTH) + 1;// 月份从1开始
|
|
||||||
final int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK) - 1; // 星期从0开始,0和7都表示周日
|
|
||||||
final int year = calendar.get(Calendar.YEAR);
|
|
||||||
|
|
||||||
return match(second, minute, hour, dayOfMonth, month, dayOfWeek, year);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -144,15 +137,7 @@ public class CronPattern {
|
|||||||
* @return 匹配到的下一个时间
|
* @return 匹配到的下一个时间
|
||||||
*/
|
*/
|
||||||
public Calendar nextMatchAfter(Calendar calendar) {
|
public Calendar nextMatchAfter(Calendar calendar) {
|
||||||
final int second = calendar.get(Calendar.SECOND);
|
return nextMatchAfter(getFields(calendar, true), calendar.getTimeZone());
|
||||||
final int minute = calendar.get(Calendar.MINUTE);
|
|
||||||
final int hour = calendar.get(Calendar.HOUR_OF_DAY);
|
|
||||||
final int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
|
|
||||||
final int month = calendar.get(Calendar.MONTH) + 1;// 月份从1开始
|
|
||||||
final int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK) - 1; // 星期从0开始,0和7都表示周日
|
|
||||||
final int year = calendar.get(Calendar.YEAR);
|
|
||||||
|
|
||||||
return nextMatchAfter(new int[]{second, minute, hour, dayOfMonth, month, dayOfWeek, year}, calendar.getTimeZone());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -196,4 +181,24 @@ public class CronPattern {
|
|||||||
// 返回匹配到的最早日期
|
// 返回匹配到的最早日期
|
||||||
return CollUtil.min(nextMatches);
|
return CollUtil.min(nextMatches);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取处理后的字段列表<br>
|
||||||
|
* 月份从1开始,周从0开始
|
||||||
|
*
|
||||||
|
* @param calendar {@link Calendar}
|
||||||
|
* @param isMatchSecond 是否匹配秒,{@link false}则秒返回-1
|
||||||
|
* @return 字段值列表
|
||||||
|
* @since 5.8.0
|
||||||
|
*/
|
||||||
|
private int[] getFields(Calendar calendar, boolean isMatchSecond) {
|
||||||
|
final int second = isMatchSecond ? calendar.get(Calendar.SECOND) : -1;
|
||||||
|
final int minute = calendar.get(Calendar.MINUTE);
|
||||||
|
final int hour = calendar.get(Calendar.HOUR_OF_DAY);
|
||||||
|
final int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
|
||||||
|
final int month = calendar.get(Calendar.MONTH) + 1;// 月份从1开始
|
||||||
|
final int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK) - 1; // 星期从0开始,0和7都表示周日
|
||||||
|
final int year = calendar.get(Calendar.YEAR);
|
||||||
|
return new int[]{second, minute, hour, dayOfMonth, month, dayOfWeek, year};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user