mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
add methon
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package cn.hutool.cron.pattern.parser;
|
||||
|
||||
import cn.hutool.core.date.Month;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.cron.CronException;
|
||||
|
||||
/**
|
||||
@@ -10,11 +12,6 @@ import cn.hutool.cron.CronException;
|
||||
*/
|
||||
public class MonthValueParser extends AbsValueParser {
|
||||
|
||||
/**
|
||||
* Months aliases.
|
||||
*/
|
||||
private static final String[] ALIASES = {"jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"};
|
||||
|
||||
public MonthValueParser() {
|
||||
super(1, 12);
|
||||
}
|
||||
@@ -31,16 +28,13 @@ public class MonthValueParser extends AbsValueParser {
|
||||
/**
|
||||
* 解析别名
|
||||
*
|
||||
* @param value 别名值
|
||||
* @return 月份int值
|
||||
* @param monthName 别名值
|
||||
* @return 月份int值,从1开始
|
||||
* @throws CronException 无效月别名抛出此异常
|
||||
*/
|
||||
private int parseAlias(String value) throws CronException {
|
||||
for (int i = 0; i < ALIASES.length; i++) {
|
||||
if (ALIASES[i].equalsIgnoreCase(value)) {
|
||||
return i + 1;
|
||||
}
|
||||
}
|
||||
throw new CronException("Invalid month alias: {}", value);
|
||||
private int parseAlias(String monthName) throws CronException {
|
||||
final Month month = Month.of(monthName);
|
||||
Assert.notNull(month, () -> new CronException("Invalid month alias: {}", monthName));
|
||||
return month.getValueBaseOne();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user