Skip to content

Commit

Permalink
Issue #57: Add test: BetweenDayOfWeekValueGenerator does not work for…
Browse files Browse the repository at this point in the history
… the first day of a month in some cases.
  • Loading branch information
jmrozanec committed Mar 5, 2016
1 parent cdf9f45 commit c39dae9
Showing 1 changed file with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,35 @@ public void testCronExpressionEveryTwoHoursSlash2() {

assertTrue(DateTime.parse("2015-08-28T14:00:00.000-03:00").compareTo(ExecutionTime.forCron(cron).nextExecution(startDateTime)) == 0);
}

/**
* Test for issue #57
* https://github.com/jmrozanec/cron-utils/issues/57
* Reported case: BetweenDayOfWeekValueGenerator does not work for the first day of a month in some cases.
* Expected: first day of month should be returned ok
*/
public void testCronExpressionBetweenDayOfWeekValueGeneratorCorrectFirstDayOfMonth() {
CronDefinition cronDefinition = CronDefinitionBuilder.defineCron()
.withMinutes().and()
.withHours().and()
.withDayOfMonth()
.supportsL().supportsW()
.and()
.withMonth().and()
.withDayOfWeek()
.withMondayDoWValue(1)
.withValidRange(1, 7)
.supportsHash().supportsL()
.and()
.withYear().and()
.lastFieldOptional().instance();

CronParser parser = new CronParser(cronDefinition);
Cron cron = parser.parse("30 3 * * MON-FRI");
DateTime sameDayBeforeEventStartDateTime = DateTime.parse("1970-01-01T00:00:00.000-03:00");
System.out.println(ExecutionTime.forCron(cron).nextExecution(sameDayBeforeEventStartDateTime));
assertEquals(1, ExecutionTime.forCron(cron).nextExecution(sameDayBeforeEventStartDateTime).getDayOfMonth());
DateTime sameDayAfterEventStartDateTime = DateTime.parse("1970-01-01T12:00:00.000-03:00");
assertEquals(2, ExecutionTime.forCron(cron).nextExecution(sameDayAfterEventStartDateTime).getDayOfMonth());
}
}

0 comments on commit c39dae9

Please sign in to comment.