mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
CronPattern support L
This commit is contained in:
@@ -8,9 +8,10 @@
|
|||||||
### 新特性
|
### 新特性
|
||||||
* 【core 】 ImgUtil.createImage支持背景透明(issue#851@Github)
|
* 【core 】 ImgUtil.createImage支持背景透明(issue#851@Github)
|
||||||
* 【json 】 更改JSON转字符串时"</"被转义的规则为不转义(issue#852@Github)
|
* 【json 】 更改JSON转字符串时"</"被转义的规则为不转义(issue#852@Github)
|
||||||
|
* 【cron 】 表达式的所有段支持L关键字(issue#849@Github)
|
||||||
|
|
||||||
### Bug修复
|
### Bug修复
|
||||||
* 【http 】 修复URL中有`&`导致的问题(issue#850@Github)
|
* 【core 】 修复URLBuilder中请求参数有`&`导致的问题(issue#850@Github)
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@@ -13,7 +13,13 @@ public class SimpleValueParser implements ValueParser {
|
|||||||
protected int min;
|
protected int min;
|
||||||
/** 最大值(包括) */
|
/** 最大值(包括) */
|
||||||
protected int max;
|
protected int max;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造
|
||||||
|
*
|
||||||
|
* @param min 最小值(包括)
|
||||||
|
* @param max 最大值(包括)
|
||||||
|
*/
|
||||||
public SimpleValueParser(int min, int max) {
|
public SimpleValueParser(int min, int max) {
|
||||||
if(min > max){
|
if(min > max){
|
||||||
this.min = max;
|
this.min = max;
|
||||||
@@ -26,6 +32,11 @@ public class SimpleValueParser implements ValueParser {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int parse(String value) throws CronException {
|
public int parse(String value) throws CronException {
|
||||||
|
if("L".equalsIgnoreCase(value)){
|
||||||
|
// L表示最大值
|
||||||
|
return max;
|
||||||
|
}
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
try {
|
try {
|
||||||
i = Integer.parseInt(value);
|
i = Integer.parseInt(value);
|
||||||
|
@@ -125,6 +125,22 @@ public class CronPatternTest {
|
|||||||
assertMatch(pattern, "2017-02-19 04:20:33");
|
assertMatch(pattern, "2017-02-19 04:20:33");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void lastTest() {
|
||||||
|
// 每月最后一天的任意时间
|
||||||
|
CronPattern pattern = new CronPattern("* * * L * ?");
|
||||||
|
assertMatch(pattern, "2017-07-31 04:20:00");
|
||||||
|
assertMatch(pattern, "2017-02-28 04:20:00");
|
||||||
|
|
||||||
|
// 最后一个月的任意时间
|
||||||
|
pattern = new CronPattern("* * * * L ?");
|
||||||
|
assertMatch(pattern, "2017-12-02 04:20:00");
|
||||||
|
|
||||||
|
// 任意天的最后时间
|
||||||
|
pattern = new CronPattern("L L L * * ?");
|
||||||
|
assertMatch(pattern, "2017-12-02 23:59:59");
|
||||||
|
}
|
||||||
|
|
||||||
@Test(expected = CronException.class)
|
@Test(expected = CronException.class)
|
||||||
public void rangeYearTest() {
|
public void rangeYearTest() {
|
||||||
// year的范围是1970~2099年,超出报错
|
// year的范围是1970~2099年,超出报错
|
||||||
|
Reference in New Issue
Block a user