|
30 | 30 | import java.util.Optional; |
31 | 31 | import java.util.TimeZone; |
32 | 32 |
|
| 33 | +import com.cronutils.model.CronType; |
| 34 | +import com.cronutils.model.definition.CronDefinition; |
| 35 | +import org.junit.Assert; |
33 | 36 | import org.junit.Before; |
34 | 37 | import org.junit.Ignore; |
35 | 38 | import org.junit.Test; |
@@ -904,6 +907,26 @@ public void testLastExecutionIssue424() { |
904 | 907 | } |
905 | 908 | } |
906 | 909 |
|
| 910 | + /** |
| 911 | + * Issue #428 |
| 912 | + * Enforce year constraints from Quartz cron definition |
| 913 | + */ |
| 914 | + @Test |
| 915 | + public void testBoundary() { |
| 916 | + ExecutionTime execution = ExecutionTime.forCron(parser.parse("0 0 12 * * ?")); |
| 917 | + // Before 1970 |
| 918 | + ZonedDateTime dateTimeBefore1970 = ZonedDateTime.of(1900, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC); |
| 919 | + Optional<ZonedDateTime> next = execution.nextExecution(dateTimeBefore1970); |
| 920 | + assertTrue(next.isPresent()); |
| 921 | + Assert.assertEquals(ZonedDateTime.of(1970, 1, 1, 12, 0, 0, 0, ZoneOffset.UTC), next.get()); |
| 922 | + |
| 923 | + // After 2099 |
| 924 | + ZonedDateTime dateTimeAfter2099 = ZonedDateTime.of(2150, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC); |
| 925 | + Optional<ZonedDateTime> last = execution.lastExecution(dateTimeAfter2099); |
| 926 | + assertTrue(last.isPresent()); |
| 927 | + Assert.assertEquals(ZonedDateTime.of(2099, 12, 31, 12, 0, 0, 0, ZoneOffset.UTC), last.get()); |
| 928 | + } |
| 929 | + |
907 | 930 | private Duration getMinimumInterval(final String quartzPattern) { |
908 | 931 | final ExecutionTime executionTime = ExecutionTime.forCron(parser.parse(quartzPattern)); |
909 | 932 | final ZonedDateTime coolDay = ZonedDateTime.of(2016, 1, 1, 0, 0, 0, 0, UTC); |
|
0 commit comments