@@ -35,7 +35,25 @@ public class Issue421Test {
3535 .instance ();
3636
3737 @ Test
38- public void testIntervals_Every5thMonths_SinceASpecificMonth () {
38+ public void testWrongIntervalsForEvery6Months () {
39+ LocalDateTime dayOfApril = LocalDateTime .of (2020 , 4 , 25 , 0 , 0 );
40+ Clock clock = Clock .fixed (dayOfApril .toInstant (ZoneOffset .UTC ), ZoneId .systemDefault ());
41+ ZonedDateTime dayOfAprilInLocalTimezone = ZonedDateTime .now (clock );
42+ System .out .println ("now: " + dayOfAprilInLocalTimezone );
43+ Cron cron = getEveryMonthFromNow (dayOfAprilInLocalTimezone , 6 ).instance ();
44+
45+ ZonedDateTime nextRun = nextRun (cron , dayOfAprilInLocalTimezone ); // first run
46+ Assert .assertEquals (2020 , nextRun .getYear ());
47+ Assert .assertEquals (10 , nextRun .getMonthValue ());
48+
49+ nextRun = nextRun (cron , nextRun ); // second
50+ System .out .println (nextRun );
51+ Assert .assertEquals (2021 , nextRun .getYear ());
52+ Assert .assertEquals (4 , nextRun .getMonthValue ());
53+ }
54+
55+ @ Test
56+ public void testIntervalsEvery5thMonthsSinceASpecificMonth () {
3957 LocalDateTime firstOfJanuary = LocalDateTime .of (2020 , 2 , 10 , 0 , 0 );
4058 Clock clock = Clock .fixed (firstOfJanuary .toInstant (ZoneOffset .UTC ), ZoneId .systemDefault ());
4159 ZonedDateTime now = ZonedDateTime .now (clock );
@@ -58,7 +76,7 @@ public void testIntervals_Every5thMonths_SinceASpecificMonth() {
5876 }
5977
6078 @ Test
61- public void testIntervals_Every5thMonth () {
79+ public void testIntervalsEvery5thMonth () {
6280 LocalDateTime firstOfJanuary = LocalDateTime .of (2020 , 2 , 10 , 0 , 0 );
6381 Clock clock = Clock .fixed (firstOfJanuary .toInstant (ZoneOffset .UTC ), ZoneId .systemDefault ());
6482 ZonedDateTime now = ZonedDateTime .now (clock );
@@ -81,7 +99,7 @@ public void testIntervals_Every5thMonth() {
8199 }
82100
83101 @ Test
84- public void testDescription_EveryXMonths () {
102+ public void testDescriptionEveryXMonths () {
85103 ZonedDateTime now = ZonedDateTime .now ();
86104
87105 String description = CronDescriptor .instance (Locale .US ).describe (getEveryMonth (now , 3 ).instance ());
@@ -109,7 +127,7 @@ public static CronBuilder getEveryMonthFromNow(ZonedDateTime now, int every) {
109127 .withDoW (questionMark ())
110128 .withDoM (on (now .getDayOfMonth ()))
111129 .withDoY (questionMark ())
112- .withMonth (every (on (now .getMonthValue ()),every ));
130+ .withMonth (every (on (now .getMonthValue ()), every ));
113131 }
114132
115133 private static ZonedDateTime nextRun (Cron cron , ZonedDateTime when ) {
0 commit comments