From 543515e36cf2cdc1cae518c6de96d5e1d9a61d46 Mon Sep 17 00:00:00 2001 From: David Syer Date: Mon, 11 Jan 2010 16:05:12 +0000 Subject: [PATCH] RESOLVED - issue SPR-6666: CronTrigger/CronSequenceGenerator fails to handle daylight saving timezone changes --- .../support/CronSequenceGenerator.java | 22 ++- .../scheduling/support/CronTrigger.java | 21 ++- .../scheduling/support/CronTriggerTests.java | 177 +++++++++++++----- 3 files changed, 156 insertions(+), 64 deletions(-) diff --git a/org.springframework.context/src/main/java/org/springframework/scheduling/support/CronSequenceGenerator.java b/org.springframework.context/src/main/java/org/springframework/scheduling/support/CronSequenceGenerator.java index 7b1f436689..d6f8791578 100644 --- a/org.springframework.context/src/main/java/org/springframework/scheduling/support/CronSequenceGenerator.java +++ b/org.springframework.context/src/main/java/org/springframework/scheduling/support/CronSequenceGenerator.java @@ -23,6 +23,7 @@ import java.util.Collections; import java.util.Date; import java.util.GregorianCalendar; import java.util.List; +import java.util.TimeZone; import org.springframework.util.StringUtils; @@ -66,13 +67,17 @@ class CronSequenceGenerator { private final String expression; + private final TimeZone timeZone; + /** * Construct a {@link CronSequenceGenerator} from the pattern provided. * @param expression a space-separated list of time fields + * @param timeZone the TimeZone to use for generated trigger times * @throws IllegalArgumentException if the pattern cannot be parsed */ - public CronSequenceGenerator(String expression) { + public CronSequenceGenerator(String expression, TimeZone timeZone) { this.expression = expression; + this.timeZone = timeZone; parse(expression); } @@ -106,6 +111,7 @@ class CronSequenceGenerator { */ Calendar calendar = new GregorianCalendar(); + calendar.setTimeZone(timeZone); calendar.setTime(date); // Truncate to the next whole second @@ -122,13 +128,13 @@ class CronSequenceGenerator { int second = calendar.get(Calendar.SECOND); List emptyList = Collections. emptyList(); - int updateSecond = findNext(this.seconds, second, 60, calendar, Calendar.SECOND, emptyList); + int updateSecond = findNext(this.seconds, second, calendar, Calendar.SECOND, Calendar.MINUTE, emptyList); if (second == updateSecond) { resets.add(Calendar.SECOND); } int minute = calendar.get(Calendar.MINUTE); - int updateMinute = findNext(this.minutes, minute, 60, calendar, Calendar.MINUTE, resets); + int updateMinute = findNext(this.minutes, minute, calendar, Calendar.MINUTE, Calendar.HOUR_OF_DAY, resets); if (minute == updateMinute) { resets.add(Calendar.MINUTE); } else { @@ -136,7 +142,7 @@ class CronSequenceGenerator { } int hour = calendar.get(Calendar.HOUR_OF_DAY); - int updateHour = findNext(this.hours, hour, 24, calendar, Calendar.HOUR_OF_DAY, resets); + int updateHour = findNext(this.hours, hour, calendar, Calendar.HOUR_OF_DAY, Calendar.DAY_OF_WEEK, resets); if (hour == updateHour) { resets.add(Calendar.HOUR_OF_DAY); } else { @@ -153,7 +159,7 @@ class CronSequenceGenerator { } int month = calendar.get(Calendar.MONTH); - int updateMonth = findNext(this.months, month, 12, calendar, Calendar.MONTH, resets); + int updateMonth = findNext(this.months, month, calendar, Calendar.MONTH, Calendar.YEAR, resets); if (month != updateMonth) { doNext(calendar); } @@ -183,7 +189,6 @@ class CronSequenceGenerator { * and reset the calendar. * @param bits a {@link BitSet} representing the allowed values of the field * @param value the current value of the field - * @param max the largest value that the field can have * @param calendar the calendar to increment as we move through the bits * @param field the field to increment in the calendar (@see * {@link Calendar} for the static constants defining valid fields) @@ -191,11 +196,12 @@ class CronSequenceGenerator { * ones of lower significance than the field of interest) * @return the value of the calendar field that is next in the sequence */ - private int findNext(BitSet bits, int value, int max, Calendar calendar, int field, List lowerOrders) { + private int findNext(BitSet bits, int value, Calendar calendar, int field, int nextField, List lowerOrders) { int nextValue = bits.nextSetBit(value); // roll over if needed if (nextValue == -1) { - calendar.add(field, max - value); + calendar.add(nextField, 1); + calendar.set(field, 0); nextValue = bits.nextSetBit(0); } if (nextValue != value) { diff --git a/org.springframework.context/src/main/java/org/springframework/scheduling/support/CronTrigger.java b/org.springframework.context/src/main/java/org/springframework/scheduling/support/CronTrigger.java index e51242bffc..37477b40fa 100644 --- a/org.springframework.context/src/main/java/org/springframework/scheduling/support/CronTrigger.java +++ b/org.springframework.context/src/main/java/org/springframework/scheduling/support/CronTrigger.java @@ -17,6 +17,7 @@ package org.springframework.scheduling.support; import java.util.Date; +import java.util.TimeZone; import org.springframework.scheduling.Trigger; import org.springframework.scheduling.TriggerContext; @@ -33,16 +34,24 @@ public class CronTrigger implements Trigger { private final CronSequenceGenerator sequenceGenerator; - /** * Build a {@link CronTrigger} from the pattern provided. * @param cronExpression a space-separated list of time fields, * following cron expression conventions + * @param timeZone a time zone in which the trigger times will be generated */ - public CronTrigger(String cronExpression) { - this.sequenceGenerator = new CronSequenceGenerator(cronExpression); + public CronTrigger(String cronExpression, TimeZone timeZone) { + this.sequenceGenerator = new CronSequenceGenerator(cronExpression, timeZone); } + /** + * Build a {@link CronTrigger} from the pattern provided in the default time zone. + * @param cronExpression a space-separated list of time fields, + * following cron expression conventions + */ + public CronTrigger(String cronExpression) { + this(cronExpression, TimeZone.getDefault()); + } public Date nextExecutionTime(TriggerContext triggerContext) { Date date = triggerContext.lastCompletionTime(); @@ -52,12 +61,10 @@ public class CronTrigger implements Trigger { return this.sequenceGenerator.next(date); } - @Override public boolean equals(Object obj) { - return (this == obj || - (obj instanceof CronTrigger && - this.sequenceGenerator.equals(((CronTrigger) obj).sequenceGenerator))); + return (this == obj || (obj instanceof CronTrigger && this.sequenceGenerator + .equals(((CronTrigger) obj).sequenceGenerator))); } @Override diff --git a/org.springframework.context/src/test/java/org/springframework/scheduling/support/CronTriggerTests.java b/org.springframework.context/src/test/java/org/springframework/scheduling/support/CronTriggerTests.java index b56ee85e1c..387b7ac54f 100644 --- a/org.springframework.context/src/test/java/org/springframework/scheduling/support/CronTriggerTests.java +++ b/org.springframework.context/src/test/java/org/springframework/scheduling/support/CronTriggerTests.java @@ -18,24 +18,45 @@ package org.springframework.scheduling.support; import static org.junit.Assert.assertEquals; +import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; +import java.util.List; +import java.util.TimeZone; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; import org.springframework.scheduling.TriggerContext; /** * @author Dave Syer * @author Mark Fisher */ +@RunWith(Parameterized.class) public class CronTriggerTests { private Calendar calendar = new GregorianCalendar(); - private Date date = new Date(); + private final Date date; + private final TimeZone timeZone; + + public CronTriggerTests(Date date, TimeZone timeZone) { + this.timeZone = timeZone; + this.date = date; + } + + @Parameters + public static List getParameters() { + List list = new ArrayList(); + list.add(new Object[] {new Date(), TimeZone.getDefault()}); + list.add(new Object[] {new Date(), TimeZone.getTimeZone("CET")}); + return list; + } /** * @param calendar @@ -48,20 +69,21 @@ public class CronTriggerTests { @Before public void setUp() { + calendar.setTimeZone(timeZone); calendar.setTime(date); roundup(calendar); } @Test public void testMatchAll() throws Exception { - CronTrigger trigger = new CronTrigger("* * * * * *"); + CronTrigger trigger = new CronTrigger("* * * * * *", timeZone); TriggerContext context = getTriggerContext(date); assertEquals(calendar.getTime(), trigger.nextExecutionTime(context)); } @Test public void testMatchLastSecond() throws Exception { - CronTrigger trigger = new CronTrigger("* * * * * *"); + CronTrigger trigger = new CronTrigger("* * * * * *", timeZone); GregorianCalendar calendar = new GregorianCalendar(); calendar.set(Calendar.SECOND, 58); assertMatchesNextSecond(trigger, calendar); @@ -69,7 +91,7 @@ public class CronTriggerTests { @Test public void testMatchSpecificSecond() throws Exception { - CronTrigger trigger = new CronTrigger("10 * * * * *"); + CronTrigger trigger = new CronTrigger("10 * * * * *", timeZone); GregorianCalendar calendar = new GregorianCalendar(); calendar.set(Calendar.SECOND, 9); assertMatchesNextSecond(trigger, calendar); @@ -77,7 +99,7 @@ public class CronTriggerTests { @Test public void testIncrementSecondByOne() throws Exception { - CronTrigger trigger = new CronTrigger("11 * * * * *"); + CronTrigger trigger = new CronTrigger("11 * * * * *", timeZone); calendar.set(Calendar.SECOND, 10); Date date = calendar.getTime(); calendar.add(Calendar.SECOND, 1); @@ -87,7 +109,7 @@ public class CronTriggerTests { @Test public void testIncrementSecondAndRollover() throws Exception { - CronTrigger trigger = new CronTrigger("10 * * * * *"); + CronTrigger trigger = new CronTrigger("10 * * * * *", timeZone); calendar.set(Calendar.SECOND, 11); Date date = calendar.getTime(); calendar.add(Calendar.SECOND, 59); @@ -97,7 +119,7 @@ public class CronTriggerTests { @Test public void testSecondRange() throws Exception { - CronTrigger trigger = new CronTrigger("10-15 * * * * *"); + CronTrigger trigger = new CronTrigger("10-15 * * * * *", timeZone); calendar.set(Calendar.SECOND, 9); assertMatchesNextSecond(trigger, calendar); calendar.set(Calendar.SECOND, 14); @@ -106,7 +128,7 @@ public class CronTriggerTests { @Test public void testIncrementMinuteByOne() throws Exception { - CronTrigger trigger = new CronTrigger("0 11 * * * *"); + CronTrigger trigger = new CronTrigger("0 11 * * * *", timeZone); calendar.set(Calendar.MINUTE, 10); Date date = calendar.getTime(); calendar.add(Calendar.MINUTE, 1); @@ -117,7 +139,7 @@ public class CronTriggerTests { @Test public void testIncrementMinute() throws Exception { - CronTrigger trigger = new CronTrigger("0 * * * * *"); + CronTrigger trigger = new CronTrigger("0 * * * * *", timeZone); calendar.set(Calendar.MINUTE, 10); Date date = calendar.getTime(); calendar.add(Calendar.MINUTE, 1); @@ -131,7 +153,7 @@ public class CronTriggerTests { @Test public void testIncrementMinuteAndRollover() throws Exception { - CronTrigger trigger = new CronTrigger("0 10 * * * *"); + CronTrigger trigger = new CronTrigger("0 10 * * * *", timeZone); calendar.set(Calendar.MINUTE, 11); calendar.set(Calendar.SECOND, 0); Date date = calendar.getTime(); @@ -142,7 +164,7 @@ public class CronTriggerTests { @Test public void testIncrementHour() throws Exception { - CronTrigger trigger = new CronTrigger("0 0 * * * *"); + CronTrigger trigger = new CronTrigger("0 0 * * * *", timeZone); calendar.set(Calendar.MONTH, 9); calendar.set(Calendar.DAY_OF_MONTH, 30); calendar.set(Calendar.HOUR_OF_DAY, 11); @@ -158,9 +180,28 @@ public class CronTriggerTests { assertEquals(calendar.getTime(), trigger.nextExecutionTime(context2)); } + @Test + public void testIncrementHourAndRollover() throws Exception { + CronTrigger trigger = new CronTrigger("0 0 * * * *", timeZone); + calendar.set(Calendar.MONTH, 9); + calendar.set(Calendar.DAY_OF_MONTH, 10); + calendar.set(Calendar.HOUR_OF_DAY, 23); + calendar.set(Calendar.MINUTE, 1); + calendar.set(Calendar.SECOND, 0); + Date date = calendar.getTime(); + calendar.set(Calendar.MINUTE, 0); + calendar.set(Calendar.HOUR_OF_DAY, 0); + calendar.set(Calendar.DAY_OF_MONTH, 11); + TriggerContext context1 = getTriggerContext(date); + assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context1)); + calendar.set(Calendar.HOUR_OF_DAY, 1); + TriggerContext context2 = getTriggerContext(date); + assertEquals(calendar.getTime(), trigger.nextExecutionTime(context2)); + } + @Test public void testIncrementDayOfMonth() throws Exception { - CronTrigger trigger = new CronTrigger("0 0 0 * * *"); + CronTrigger trigger = new CronTrigger("0 0 0 * * *", timeZone); calendar.set(Calendar.DAY_OF_MONTH, 1); Date date = calendar.getTime(); calendar.add(Calendar.DAY_OF_MONTH, 1); @@ -178,7 +219,7 @@ public class CronTriggerTests { @Test public void testIncrementDayOfMonthByOne() throws Exception { - CronTrigger trigger = new CronTrigger("* * * 10 * *"); + CronTrigger trigger = new CronTrigger("* * * 10 * *", timeZone); calendar.set(Calendar.DAY_OF_MONTH, 9); Date date = calendar.getTime(); calendar.add(Calendar.DAY_OF_MONTH, 1); @@ -191,7 +232,7 @@ public class CronTriggerTests { @Test public void testIncrementDayOfMonthAndRollover() throws Exception { - CronTrigger trigger = new CronTrigger("* * * 10 * *"); + CronTrigger trigger = new CronTrigger("* * * 10 * *", timeZone); calendar.set(Calendar.DAY_OF_MONTH, 11); Date date = calendar.getTime(); calendar.add(Calendar.MONTH, 1); @@ -205,7 +246,7 @@ public class CronTriggerTests { @Test public void testDailyTriggerInShortMonth() throws Exception { - CronTrigger trigger = new CronTrigger("0 0 0 * * *"); + CronTrigger trigger = new CronTrigger("0 0 0 * * *", timeZone); calendar.set(Calendar.MONTH, 8); // September: 30 days calendar.set(Calendar.DAY_OF_MONTH, 30); Date date = calendar.getTime(); @@ -223,8 +264,26 @@ public class CronTriggerTests { @Test public void testDailyTriggerInLongMonth() throws Exception { - CronTrigger trigger = new CronTrigger("0 0 0 * * *"); - calendar.set(Calendar.MONTH, 9); // October: 31 days + CronTrigger trigger = new CronTrigger("0 0 0 * * *", timeZone); + calendar.set(Calendar.MONTH, 7); // August: 31 days and not a daylight saving boundary + calendar.set(Calendar.DAY_OF_MONTH, 30); + Date date = calendar.getTime(); + calendar.set(Calendar.HOUR_OF_DAY, 0); + calendar.set(Calendar.MINUTE, 0); + calendar.set(Calendar.SECOND, 0); + calendar.set(Calendar.DAY_OF_MONTH, 31); + TriggerContext context1 = getTriggerContext(date); + assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context1)); + calendar.set(Calendar.MONTH, 8); // September + calendar.set(Calendar.DAY_OF_MONTH, 1); + TriggerContext context2 = getTriggerContext(date); + assertEquals(calendar.getTime(), trigger.nextExecutionTime(context2)); + } + + @Test + public void testDailyTriggerOnDaylightSavingBoundary() throws Exception { + CronTrigger trigger = new CronTrigger("0 0 0 * * *", timeZone); + calendar.set(Calendar.MONTH, 9); // October: 31 days and a daylight saving boundary in CET calendar.set(Calendar.DAY_OF_MONTH, 30); Date date = calendar.getTime(); calendar.set(Calendar.HOUR_OF_DAY, 0); @@ -241,7 +300,7 @@ public class CronTriggerTests { @Test public void testIncrementMonth() throws Exception { - CronTrigger trigger = new CronTrigger("0 0 0 1 * *"); + CronTrigger trigger = new CronTrigger("0 0 0 1 * *", timeZone); calendar.set(Calendar.MONTH, 9); calendar.set(Calendar.DAY_OF_MONTH, 30); Date date = calendar.getTime(); @@ -257,9 +316,29 @@ public class CronTriggerTests { assertEquals(calendar.getTime(), trigger.nextExecutionTime(context2)); } + @Test + public void testIncrementMonthAndRollover() throws Exception { + CronTrigger trigger = new CronTrigger("0 0 0 1 * *", timeZone); + calendar.set(Calendar.MONTH, 11); + calendar.set(Calendar.DAY_OF_MONTH, 31); + calendar.set(Calendar.YEAR, 2010); + Date date = calendar.getTime(); + calendar.set(Calendar.DAY_OF_MONTH, 1); + calendar.set(Calendar.HOUR_OF_DAY, 0); + calendar.set(Calendar.MINUTE, 0); + calendar.set(Calendar.SECOND, 0); + calendar.set(Calendar.MONTH, 0); + calendar.set(Calendar.YEAR, 2011); + TriggerContext context1 = getTriggerContext(date); + assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context1)); + calendar.set(Calendar.MONTH, 1); + TriggerContext context2 = getTriggerContext(date); + assertEquals(calendar.getTime(), trigger.nextExecutionTime(context2)); + } + @Test public void testMonthlyTriggerInLongMonth() throws Exception { - CronTrigger trigger = new CronTrigger("0 0 0 31 * *"); + CronTrigger trigger = new CronTrigger("0 0 0 31 * *", timeZone); calendar.set(Calendar.MONTH, 9); calendar.set(Calendar.DAY_OF_MONTH, 30); Date date = calendar.getTime(); @@ -273,7 +352,7 @@ public class CronTriggerTests { @Test public void testMonthlyTriggerInShortMonth() throws Exception { - CronTrigger trigger = new CronTrigger("0 0 0 1 * *"); + CronTrigger trigger = new CronTrigger("0 0 0 1 * *", timeZone); calendar.set(Calendar.MONTH, 9); calendar.set(Calendar.DAY_OF_MONTH, 30); Date date = calendar.getTime(); @@ -288,7 +367,7 @@ public class CronTriggerTests { @Test public void testIncrementDayOfWeekByOne() throws Exception { - CronTrigger trigger = new CronTrigger("* * * * * 2"); + CronTrigger trigger = new CronTrigger("* * * * * 2", timeZone); calendar.set(Calendar.DAY_OF_WEEK, 2); Date date = calendar.getTime(); calendar.add(Calendar.DAY_OF_WEEK, 1); @@ -302,7 +381,7 @@ public class CronTriggerTests { @Test public void testIncrementDayOfWeekAndRollover() throws Exception { - CronTrigger trigger = new CronTrigger("* * * * * 2"); + CronTrigger trigger = new CronTrigger("* * * * * 2", timeZone); calendar.set(Calendar.DAY_OF_WEEK, 4); Date date = calendar.getTime(); calendar.add(Calendar.DAY_OF_MONTH, 6); @@ -316,7 +395,7 @@ public class CronTriggerTests { @Test public void testSpecificMinuteSecond() throws Exception { - CronTrigger trigger = new CronTrigger("55 5 * * * *"); + CronTrigger trigger = new CronTrigger("55 5 * * * *", timeZone); calendar.set(Calendar.MINUTE, 4); calendar.set(Calendar.SECOND, 54); Date date = calendar.getTime(); @@ -331,7 +410,7 @@ public class CronTriggerTests { @Test public void testSpecificHourSecond() throws Exception { - CronTrigger trigger = new CronTrigger("55 * 2 * * *"); + CronTrigger trigger = new CronTrigger("55 * 2 * * *", timeZone); calendar.set(Calendar.HOUR_OF_DAY, 1); calendar.set(Calendar.SECOND, 54); Date date = calendar.getTime(); @@ -347,7 +426,7 @@ public class CronTriggerTests { @Test public void testSpecificMinuteHour() throws Exception { - CronTrigger trigger = new CronTrigger("* 5 10 * * *"); + CronTrigger trigger = new CronTrigger("* 5 10 * * *", timeZone); calendar.set(Calendar.MINUTE, 4); calendar.set(Calendar.HOUR_OF_DAY, 9); Date date = calendar.getTime(); @@ -364,7 +443,7 @@ public class CronTriggerTests { @Test public void testSpecificDayOfMonthSecond() throws Exception { - CronTrigger trigger = new CronTrigger("55 * * 3 * *"); + CronTrigger trigger = new CronTrigger("55 * * 3 * *", timeZone); calendar.set(Calendar.DAY_OF_MONTH, 2); calendar.set(Calendar.SECOND, 54); Date date = calendar.getTime(); @@ -381,7 +460,7 @@ public class CronTriggerTests { @Test public void testSpecificDate() throws Exception { - CronTrigger trigger = new CronTrigger("* * * 3 10 *"); + CronTrigger trigger = new CronTrigger("* * * 3 10 *", timeZone); calendar.set(Calendar.DAY_OF_MONTH, 2); calendar.set(Calendar.MONTH, 10); Date date = calendar.getTime(); @@ -398,10 +477,10 @@ public class CronTriggerTests { @Test public void testWeekDaySequence() throws Exception { - CronTrigger trigger = new CronTrigger("0 0 7 ? * MON-FRI"); + CronTrigger trigger = new CronTrigger("0 0 7 ? * MON-FRI", timeZone); // This is a Saturday calendar.set(2009, 8, 26); - date = calendar.getTime(); + Date date = calendar.getTime(); // 7 am is the trigger time calendar.set(Calendar.HOUR_OF_DAY, 7); calendar.set(Calendar.MINUTE, 0); @@ -421,71 +500,71 @@ public class CronTriggerTests { @Test public void testDayOfWeekIndifferent() throws Exception { - CronTrigger trigger1 = new CronTrigger("* * * 2 * *"); - CronTrigger trigger2 = new CronTrigger("* * * 2 * ?"); + CronTrigger trigger1 = new CronTrigger("* * * 2 * *", timeZone); + CronTrigger trigger2 = new CronTrigger("* * * 2 * ?", timeZone); assertEquals(trigger1, trigger2); } @Test public void testSecondIncrementer() throws Exception { - CronTrigger trigger1 = new CronTrigger("57,59 * * * * *"); - CronTrigger trigger2 = new CronTrigger("57/2 * * * * *"); + CronTrigger trigger1 = new CronTrigger("57,59 * * * * *", timeZone); + CronTrigger trigger2 = new CronTrigger("57/2 * * * * *", timeZone); assertEquals(trigger1, trigger2); } @Test public void testSecondIncrementerWithRange() throws Exception { - CronTrigger trigger1 = new CronTrigger("1,3,5 * * * * *"); - CronTrigger trigger2 = new CronTrigger("1-6/2 * * * * *"); + CronTrigger trigger1 = new CronTrigger("1,3,5 * * * * *", timeZone); + CronTrigger trigger2 = new CronTrigger("1-6/2 * * * * *", timeZone); assertEquals(trigger1, trigger2); } @Test public void testHourIncrementer() throws Exception { - CronTrigger trigger1 = new CronTrigger("* * 4,8,12,16,20 * * *"); - CronTrigger trigger2 = new CronTrigger("* * 4/4 * * *"); + CronTrigger trigger1 = new CronTrigger("* * 4,8,12,16,20 * * *", timeZone); + CronTrigger trigger2 = new CronTrigger("* * 4/4 * * *", timeZone); assertEquals(trigger1, trigger2); } @Test public void testDayNames() throws Exception { - CronTrigger trigger1 = new CronTrigger("* * * * * 0-6"); - CronTrigger trigger2 = new CronTrigger("* * * * * TUE,WED,THU,FRI,SAT,SUN,MON"); + CronTrigger trigger1 = new CronTrigger("* * * * * 0-6", timeZone); + CronTrigger trigger2 = new CronTrigger("* * * * * TUE,WED,THU,FRI,SAT,SUN,MON", timeZone); assertEquals(trigger1, trigger2); } @Test public void testSundayIsZero() throws Exception { - CronTrigger trigger1 = new CronTrigger("* * * * * 0"); - CronTrigger trigger2 = new CronTrigger("* * * * * SUN"); + CronTrigger trigger1 = new CronTrigger("* * * * * 0", timeZone); + CronTrigger trigger2 = new CronTrigger("* * * * * SUN", timeZone); assertEquals(trigger1, trigger2); } @Test public void testSundaySynonym() throws Exception { - CronTrigger trigger1 = new CronTrigger("* * * * * 0"); - CronTrigger trigger2 = new CronTrigger("* * * * * 7"); + CronTrigger trigger1 = new CronTrigger("* * * * * 0", timeZone); + CronTrigger trigger2 = new CronTrigger("* * * * * 7", timeZone); assertEquals(trigger1, trigger2); } @Test public void testMonthNames() throws Exception { - CronTrigger trigger1 = new CronTrigger("* * * * 0-11 *"); - CronTrigger trigger2 = new CronTrigger("* * * * FEB,JAN,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV,DEC *"); + CronTrigger trigger1 = new CronTrigger("* * * * 0-11 *", timeZone); + CronTrigger trigger2 = new CronTrigger("* * * * FEB,JAN,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV,DEC *", timeZone); assertEquals(trigger1, trigger2); } @Test public void testMonthNamesMixedCase() throws Exception { - CronTrigger trigger1 = new CronTrigger("* * * * 1 *"); - CronTrigger trigger2 = new CronTrigger("* * * * Feb *"); + CronTrigger trigger1 = new CronTrigger("* * * * 1 *", timeZone); + CronTrigger trigger2 = new CronTrigger("* * * * Feb *", timeZone); assertEquals(trigger1, trigger2); } @Test public void testWhitespace() throws Exception { - CronTrigger trigger1 = new CronTrigger("* * * * 1 *"); - CronTrigger trigger2 = new CronTrigger("* * * * 1 *"); + CronTrigger trigger1 = new CronTrigger("* * * * 1 *", timeZone); + CronTrigger trigger2 = new CronTrigger("* * * * 1 *", timeZone); assertEquals(trigger1, trigger2); }