AMQ-5645 - Updated DayOfMonth cron to roll to next month properly.

This commit is contained in:
Matt Warhaftig 2015-03-09 08:22:55 -04:00 committed by Timothy Bish
parent 638c1e44b1
commit 7738e862ae
2 changed files with 47 additions and 1 deletions

View File

@ -324,7 +324,7 @@ public class CronParser {
CronEntry hours = new CronEntry("Hours", tokens.get(HOURS), 0, 24);
hours.currentWhen = calculateValues(hours);
result.add(hours);
CronEntry dayOfMonth = new CronEntry("DayOfMonth", tokens.get(DAY_OF_MONTH), 1, 31);
CronEntry dayOfMonth = new CronEntry("DayOfMonth", tokens.get(DAY_OF_MONTH), 1, 32);
dayOfMonth.currentWhen = calculateValues(dayOfMonth);
result.add(dayOfMonth);
CronEntry month = new CronEntry("Month", tokens.get(MONTH), 1, 12);

View File

@ -187,6 +187,52 @@ public class CronParserTest {
assertEquals(2010,result.get(Calendar.YEAR));
}
@Test
public void testgetStartNextMonth() throws MessageFormatException {
// using an absolute date so that result will be absolute - Wednesday 15 Dec 2010
Calendar current = Calendar.getInstance();
current.set(2010, Calendar.DECEMBER, 15, 9, 15, 30);
LOG.debug("start:" + current.getTime());
String test = "* * 1 * *";
long next = CronParser.getNextScheduledTime(test, current.getTimeInMillis());
Calendar result = Calendar.getInstance();
result.setTimeInMillis(next);
LOG.debug("next:" + result.getTime());
assertEquals(0,result.get(Calendar.SECOND));
assertEquals(0,result.get(Calendar.MINUTE));
assertEquals(0,result.get(Calendar.HOUR_OF_DAY));
assertEquals(1,result.get(Calendar.DAY_OF_MONTH));
assertEquals(Calendar.JANUARY,result.get(Calendar.MONTH));
assertEquals(2011,result.get(Calendar.YEAR));
}
@Test
public void testgetNextStartCurrMonth() throws MessageFormatException {
// using an absolute date so that result will be absolute - Wednesday 15 Dec 2010
Calendar current = Calendar.getInstance();
current.set(2010, Calendar.DECEMBER, 15, 9, 15, 30);
LOG.debug("start:" + current.getTime());
String test = "* * 1 12 *";
long next = CronParser.getNextScheduledTime(test, current.getTimeInMillis());
Calendar result = Calendar.getInstance();
result.setTimeInMillis(next);
LOG.debug("next:" + result.getTime());
assertEquals(0,result.get(Calendar.SECOND));
assertEquals(0,result.get(Calendar.MINUTE));
assertEquals(0,result.get(Calendar.HOUR_OF_DAY));
assertEquals(1,result.get(Calendar.DAY_OF_MONTH));
assertEquals(Calendar.DECEMBER,result.get(Calendar.MONTH));
assertEquals(2011,result.get(Calendar.YEAR));
}
@Test
public void testgetNextTimeDays() throws MessageFormatException {