use of cn.hutool.cron.pattern.CronPattern in project hutool by looly.
the class CronTest method quartzPatternTest.
@Test
public void quartzPatternTest() {
CronPattern pattern = new CronPattern("* 0 4 * * ?");
assertMatch(pattern, "2017-02-09 04:00:00");
assertMatch(pattern, "2017-02-19 04:00:33");
// 6位Quartz风格表达式
pattern = new CronPattern("* 0 4 * * ?");
assertMatch(pattern, "2017-02-09 04:00:00");
assertMatch(pattern, "2017-02-19 04:00:33");
}
use of cn.hutool.cron.pattern.CronPattern in project hutool by looly.
the class CronTest method CronPatternTest.
@Test
public void CronPatternTest() {
CronPattern pattern;
// 任何时间匹配
pattern = new CronPattern("* * * * *");
Assert.assertTrue(pattern.match(DateUtil.current(false), true));
Assert.assertTrue(pattern.match(DateUtil.current(false), false));
// 12:11匹配
pattern = new CronPattern("39 11 12 * * *");
assertMatch(pattern, "12:11:39");
// 每5分钟匹配,匹配分钟为:[0,5,10,15,20,25,30,35,40,45,50,55]
pattern = new CronPattern("39 */5 * * * *");
assertMatch(pattern, "12:00:39");
assertMatch(pattern, "12:05:39");
assertMatch(pattern, "12:10:39");
assertMatch(pattern, "12:15:39");
assertMatch(pattern, "12:20:39");
assertMatch(pattern, "12:25:39");
assertMatch(pattern, "12:30:39");
assertMatch(pattern, "12:35:39");
assertMatch(pattern, "12:40:39");
assertMatch(pattern, "12:45:39");
assertMatch(pattern, "12:50:39");
assertMatch(pattern, "12:55:39");
// 2:01,3:01,4:01
pattern = new CronPattern("39 1 2-4 * * *");
assertMatch(pattern, "02:01:39");
assertMatch(pattern, "03:01:39");
assertMatch(pattern, "04:01:39");
// 2:01,3:01,4:01
pattern = new CronPattern("39 1 2,3,4 * * *");
assertMatch(pattern, "02:01:39");
assertMatch(pattern, "03:01:39");
assertMatch(pattern, "04:01:39");
// 08-07, 08-06
pattern = new CronPattern("39 0 0 6,7 8 *");
assertMatch(pattern, "2016-08-07 00:00:39");
assertMatch(pattern, "2016-08-06 00:00:39");
// 别名忽略大小写
pattern = new CronPattern("39 0 0 6,7 Aug *");
assertMatch(pattern, "2016-08-06 00:00:39");
assertMatch(pattern, "2016-08-07 00:00:39");
pattern = new CronPattern("39 0 0 7 aug *");
assertMatch(pattern, "2016-08-07 00:00:39");
// 星期四
pattern = new CronPattern("39 0 0 * * Thu");
assertMatch(pattern, "2017-02-09 00:00:39");
assertMatch(pattern, "2017-02-09 00:00:39");
}
use of cn.hutool.cron.pattern.CronPattern in project hutool by looly.
the class TaskTableTest method toStringTest.
@Test
@Ignore
public void toStringTest() {
final TaskTable taskTable = new TaskTable();
taskTable.add(IdUtil.fastUUID(), new CronPattern("*/10 * * * * *"), () -> Console.log("Task 1"));
taskTable.add(IdUtil.fastUUID(), new CronPattern("*/20 * * * * *"), () -> Console.log("Task 2"));
taskTable.add(IdUtil.fastUUID(), new CronPattern("*/30 * * * * *"), () -> Console.log("Task 3"));
Console.log(taskTable);
}
use of cn.hutool.cron.pattern.CronPattern in project Jpom by dromara.
the class BaseServerController method checkCron.
/**
* 验证 cron 表达式, demo 账号不能开启 cron
*
* @param cron cron
* @return 原样返回
*/
protected String checkCron(String cron) {
if (StrUtil.isNotEmpty(cron)) {
UserModel user = getUser();
Assert.state(!user.isDemoUser(), PermissionInterceptor.DEMO_TIP);
try {
new CronPattern(cron);
} catch (Exception e) {
throw new IllegalArgumentException("cron 表达式格式不正确");
}
}
return ObjectUtil.defaultIfNull(cron, StrUtil.EMPTY);
}
use of cn.hutool.cron.pattern.CronPattern in project hutool by looly.
the class CronTest method quartzRangePatternTest.
@Test
public void quartzRangePatternTest() {
CronPattern pattern = new CronPattern("* 20/2 * * * ?");
assertMatch(pattern, "2017-02-09 04:20:00");
assertMatch(pattern, "2017-02-09 05:20:00");
assertMatch(pattern, "2017-02-19 04:22:33");
pattern = new CronPattern("* 2-20/2 * * * ?");
assertMatch(pattern, "2017-02-09 04:02:00");
assertMatch(pattern, "2017-02-09 05:04:00");
assertMatch(pattern, "2017-02-19 04:20:33");
}
Aggregations