This commit is contained in:
Looly
2022-03-27 20:01:02 +08:00
parent c2e1bbafc8
commit 5966dcc626
13 changed files with 300 additions and 326 deletions

View File

@@ -2,6 +2,7 @@ package cn.hutool.cron.pattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.Console;
import org.junit.Assert;
import org.junit.Test;
import java.util.Calendar;
@@ -13,7 +14,9 @@ public class CronPatternNextMatchTest {
CronPattern pattern = new CronPattern("23 12 * 12 * * *");
//noinspection ConstantConditions
final Calendar calendar = pattern.nextMatchAfter(
DateUtil.parse("2022-04-12 09:12:23").toCalendar());
DateUtil.parse("2022-04-12 09:12:12").toCalendar());
Console.log(DateUtil.date(calendar));
Assert.assertTrue(pattern.match(calendar, true));
}
}

View File

@@ -122,6 +122,14 @@ public class CronPatternTest {
assertMatch(pattern, "2017-02-19 04:00:33");
}
@Test
public void patternNegativeTest() {
// -4表示倒数的数字此处在小时上-4表示 23 - 4为19
CronPattern pattern = CronPattern.of("* 0 -4 * * ?");
assertMatch(pattern, "2017-02-09 19:00:00");
assertMatch(pattern, "2017-02-19 19:00:33");
}
@Test
public void rangePatternTest() {
CronPattern pattern = CronPattern.of("* 20/2 * * * ?");