diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/scheduling/CronSequenceGenerator.java b/org.springframework.integration/src/main/java/org/springframework/integration/scheduling/CronSequenceGenerator.java index b173cfb807..56cb676f32 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/scheduling/CronSequenceGenerator.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/scheduling/CronSequenceGenerator.java @@ -94,9 +94,7 @@ public class CronSequenceGenerator { int minute = calendar.get(Calendar.MINUTE); int hour = calendar.get(Calendar.HOUR_OF_DAY); - // the DAY_OF_WEEK values in java.util.Calendar start with 1 (Sunday), - // but in the cron pattern, they start with 0, so we subtract 1 here - int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK) - 1; + int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK); int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH); int month = calendar.get(Calendar.MONTH); @@ -118,7 +116,9 @@ public class CronSequenceGenerator { private int findNextDay(Calendar calendar, BitSet daysOfMonth, int dayOfMonth, BitSet daysOfWeek, int dayOfWeek, int max) { int count = 0; - while ((!daysOfMonth.get(dayOfMonth) || !daysOfWeek.get(dayOfWeek)) && count++ < max) { + // the DAY_OF_WEEK values in java.util.Calendar start with 1 (Sunday), + // but in the cron pattern, they start with 0, so we subtract 1 here + while ((!daysOfMonth.get(dayOfMonth) || !daysOfWeek.get(dayOfWeek - 1)) && count++ < max) { calendar.add(Calendar.DAY_OF_MONTH, 1); dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH); dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK); diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/scheduling/CronTriggerTests.java b/org.springframework.integration/src/test/java/org/springframework/integration/scheduling/CronTriggerTests.java index fbebf41dd6..354904c637 100644 --- a/org.springframework.integration/src/test/java/org/springframework/integration/scheduling/CronTriggerTests.java +++ b/org.springframework.integration/src/test/java/org/springframework/integration/scheduling/CronTriggerTests.java @@ -148,7 +148,7 @@ public class CronTriggerTests { @Test public void testIncrementDayOfWeekByOne() throws Exception { CronTrigger trigger = new CronTrigger("* * * * * 2"); - calendar.set(Calendar.DAY_OF_WEEK, 1); + calendar.set(Calendar.DAY_OF_WEEK, 2); Date date = calendar.getTime(); calendar.add(Calendar.DAY_OF_WEEK, 1); calendar.set(Calendar.HOUR_OF_DAY, 0); @@ -160,7 +160,7 @@ public class CronTriggerTests { @Test public void testIncrementDayOfWeekAndRollover() throws Exception { CronTrigger trigger = new CronTrigger("* * * * * 2"); - calendar.set(Calendar.DAY_OF_WEEK, 3); + calendar.set(Calendar.DAY_OF_WEEK, 4); Date date = calendar.getTime(); calendar.add(Calendar.DAY_OF_MONTH, 6); calendar.set(Calendar.HOUR_OF_DAY, 0);