@@ -34,29 +34,54 @@ public class Issue421Test {
3434 .withCronValidation (CronConstraintsFactory .ensureEitherDayOfYearOrMonth ())
3535 .instance ();
3636
37- @ Ignore
3837 @ Test
39- public void testWrongIntervalsForEvery6Months () {
40- LocalDateTime firstOfJanuary = LocalDateTime .of (2020 , 4 , 25 , 0 , 0 );
38+ public void testIntervals_Every5thMonths_SinceASpecificMonth () {
39+ LocalDateTime firstOfJanuary = LocalDateTime .of (2020 , 2 , 10 , 0 , 0 );
4140 Clock clock = Clock .fixed (firstOfJanuary .toInstant (ZoneOffset .UTC ), ZoneId .systemDefault ());
4241 ZonedDateTime now = ZonedDateTime .now (clock );
4342 System .out .println ("now: " + now );
4443
45- Cron cron = getEveryMonth (now , 6 ).instance ();
44+ Cron cron = getEveryMonthFromNow (now , 5 ).instance ();
4645 ZonedDateTime nextRun ;
4746
4847 nextRun = nextRun (cron , now ); // first run
4948 Assert .assertEquals (2020 , nextRun .getYear ());
50- Assert .assertEquals (10 , nextRun .getMonthValue ());
49+ Assert .assertEquals (7 , nextRun .getMonthValue ());
5150
52- nextRun = nextRun (cron , nextRun ); // second
51+ nextRun = nextRun (cron , nextRun ); // first run
52+ Assert .assertEquals (2020 , nextRun .getYear ());
53+ Assert .assertEquals (12 , nextRun .getMonthValue ());
54+
55+ nextRun = nextRun (cron , nextRun ); // first run
56+ Assert .assertEquals (2021 , nextRun .getYear ());
57+ Assert .assertEquals (2 , nextRun .getMonthValue ());
58+ }
59+
60+ @ Test
61+ public void testIntervals_Every5thMonth () {
62+ LocalDateTime firstOfJanuary = LocalDateTime .of (2020 , 2 , 10 , 0 , 0 );
63+ Clock clock = Clock .fixed (firstOfJanuary .toInstant (ZoneOffset .UTC ), ZoneId .systemDefault ());
64+ ZonedDateTime now = ZonedDateTime .now (clock );
65+ System .out .println ("now: " + now );
66+
67+ Cron cron = getEveryMonth (now , 5 ).instance ();
68+ ZonedDateTime nextRun ;
69+
70+ nextRun = nextRun (cron , now ); // first run
71+ Assert .assertEquals (2020 , nextRun .getYear ());
72+ Assert .assertEquals (6 , nextRun .getMonthValue ());
73+
74+ nextRun = nextRun (cron , nextRun ); // first run
75+ Assert .assertEquals (2020 , nextRun .getYear ());
76+ Assert .assertEquals (11 , nextRun .getMonthValue ());
77+
78+ nextRun = nextRun (cron , nextRun ); // first run
5379 Assert .assertEquals (2021 , nextRun .getYear ());
54- Assert .assertEquals (4 , nextRun .getMonthValue ());
80+ Assert .assertEquals (1 , nextRun .getMonthValue ());
5581 }
5682
57- @ Ignore
5883 @ Test
59- public void testWrongEveryXMonthsDescription () {
84+ public void testDescription_EveryXMonths () {
6085 ZonedDateTime now = ZonedDateTime .now ();
6186
6287 String description = CronDescriptor .instance (Locale .US ).describe (getEveryMonth (now , 3 ).instance ());
@@ -77,6 +102,15 @@ public static CronBuilder getEveryMonth(ZonedDateTime now, int every) {
77102 .withDoY (questionMark ())
78103 .withMonth (every (every ));
79104 }
105+ public static CronBuilder getEveryMonthFromNow (ZonedDateTime now , int every ) {
106+ return CronBuilder .cron (definition )
107+ .withMinute (on (now .getMinute ()))
108+ .withHour (on (now .getHour ()))
109+ .withDoW (questionMark ())
110+ .withDoM (on (now .getDayOfMonth ()))
111+ .withDoY (questionMark ())
112+ .withMonth (every (on (now .getMonthValue ()),every ));
113+ }
80114
81115 private static ZonedDateTime nextRun (Cron cron , ZonedDateTime when ) {
82116 final Optional <ZonedDateTime > next = ExecutionTime .forCron (cron ).nextExecution (when );
0 commit comments