@@ -32,29 +32,54 @@ public class Issue421Test {
3232 .withCronValidation (CronConstraintsFactory .ensureEitherDayOfYearOrMonth ())
3333 .instance ();
3434
35- @ Ignore
3635 @ Test
37- public void testWrongIntervalsForEvery6Months () {
38- LocalDateTime firstOfJanuary = LocalDateTime .of (2020 , 4 , 25 , 0 , 0 );
36+ public void testIntervals_Every5thMonths_SinceASpecificMonth () {
37+ LocalDateTime firstOfJanuary = LocalDateTime .of (2020 , 2 , 10 , 0 , 0 );
3938 Clock clock = Clock .fixed (firstOfJanuary .toInstant (ZoneOffset .UTC ), ZoneId .systemDefault ());
4039 ZonedDateTime now = ZonedDateTime .now (clock );
4140 System .out .println ("now: " + now );
4241
43- Cron cron = getEveryMonth (now , 6 ).instance ();
42+ Cron cron = getEveryMonthFromNow (now , 5 ).instance ();
4443 ZonedDateTime nextRun ;
4544
4645 nextRun = nextRun (cron , now ); // first run
4746 Assert .assertEquals (2020 , nextRun .getYear ());
48- Assert .assertEquals (10 , nextRun .getMonthValue ());
47+ Assert .assertEquals (7 , nextRun .getMonthValue ());
4948
50- nextRun = nextRun (cron , nextRun ); // second
49+ nextRun = nextRun (cron , nextRun ); // first run
50+ Assert .assertEquals (2020 , nextRun .getYear ());
51+ Assert .assertEquals (12 , nextRun .getMonthValue ());
52+
53+ nextRun = nextRun (cron , nextRun ); // first run
54+ Assert .assertEquals (2021 , nextRun .getYear ());
55+ Assert .assertEquals (2 , nextRun .getMonthValue ());
56+ }
57+
58+ @ Test
59+ public void testIntervals_Every5thMonth () {
60+ LocalDateTime firstOfJanuary = LocalDateTime .of (2020 , 2 , 10 , 0 , 0 );
61+ Clock clock = Clock .fixed (firstOfJanuary .toInstant (ZoneOffset .UTC ), ZoneId .systemDefault ());
62+ ZonedDateTime now = ZonedDateTime .now (clock );
63+ System .out .println ("now: " + now );
64+
65+ Cron cron = getEveryMonth (now , 5 ).instance ();
66+ ZonedDateTime nextRun ;
67+
68+ nextRun = nextRun (cron , now ); // first run
69+ Assert .assertEquals (2020 , nextRun .getYear ());
70+ Assert .assertEquals (6 , nextRun .getMonthValue ());
71+
72+ nextRun = nextRun (cron , nextRun ); // first run
73+ Assert .assertEquals (2020 , nextRun .getYear ());
74+ Assert .assertEquals (11 , nextRun .getMonthValue ());
75+
76+ nextRun = nextRun (cron , nextRun ); // first run
5177 Assert .assertEquals (2021 , nextRun .getYear ());
52- Assert .assertEquals (4 , nextRun .getMonthValue ());
78+ Assert .assertEquals (1 , nextRun .getMonthValue ());
5379 }
5480
55- @ Ignore
5681 @ Test
57- public void testWrongEveryXMonthsDescription () {
82+ public void testDescription_EveryXMonths () {
5883 ZonedDateTime now = ZonedDateTime .now ();
5984
6085 String description = CronDescriptor .instance (Locale .US ).describe (getEveryMonth (now , 3 ).instance ());
@@ -75,6 +100,15 @@ public static CronBuilder getEveryMonth(ZonedDateTime now, int every) {
75100 .withDoY (questionMark ())
76101 .withMonth (every (every ));
77102 }
103+ public static CronBuilder getEveryMonthFromNow (ZonedDateTime now , int every ) {
104+ return CronBuilder .cron (definition )
105+ .withMinute (on (now .getMinute ()))
106+ .withHour (on (now .getHour ()))
107+ .withDoW (questionMark ())
108+ .withDoM (on (now .getDayOfMonth ()))
109+ .withDoY (questionMark ())
110+ .withMonth (every (on (now .getMonthValue ()),every ));
111+ }
78112
79113 private static ZonedDateTime nextRun (Cron cron , ZonedDateTime when ) {
80114 final Optional <ZonedDateTime > next = ExecutionTime .forCron (cron ).nextExecution (when );
0 commit comments