You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by xu...@apache.org on 2011/05/10 10:55:54 UTC

svn commit: r1101367 - in /openejb/trunk/openejb3/container/openejb-core/src: main/java/org/apache/openejb/core/timer/EJBCronTrigger.java test/java/org/apache/openejb/timer/EJBCronTriggerTest.java

Author: xuhaihong
Date: Tue May 10 08:55:54 2011
New Revision: 1101367

URL: http://svn.apache.org/viewvc?rev=1101367&view=rev
Log:
OPENEJB-1540 Many boudary values don't work well in calendar based trigger. (Patch from Shawn Jiang)

Modified:
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/timer/EJBCronTrigger.java
    openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/timer/EJBCronTriggerTest.java

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/timer/EJBCronTrigger.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/timer/EJBCronTrigger.java?rev=1101367&r1=1101366&r2=1101367&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/timer/EJBCronTrigger.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/timer/EJBCronTrigger.java Tue May 10 08:55:54 2011
@@ -23,10 +23,8 @@ import java.util.Collections;
 import java.util.Date;
 import java.util.GregorianCalendar;
 import java.util.HashMap;
-import java.util.HashSet;
 import java.util.LinkedHashMap;
 import java.util.List;
-import java.util.ListIterator;
 import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
@@ -46,6 +44,8 @@ import org.apache.openejb.util.LogCatego
 import org.apache.openejb.util.Logger;
 
 public class EJBCronTrigger extends Trigger {
+    
+    private static final Logger log = Logger.getInstance(LogCategory.TIMER, EJBCronTrigger.class);
 
     private static final Pattern INCREMENTS = Pattern.compile("(\\d+|\\*)/(\\d+)*");
 
@@ -72,8 +72,8 @@ public class EJBCronTrigger extends Trig
     private static final Map<String, Integer> WEEKDAYS_MAP = new HashMap<String, Integer>();
 
     static {
-        int i = 1;
-        // Jan -> 1
+        int i = 0;
+        // Jan -> 0
         for (String month : new DateFormatSymbols(Locale.US).getShortMonths()) {
             MONTHS_MAP.put(month.toUpperCase(Locale.US), i++);
         }
@@ -112,6 +112,7 @@ public class EJBCronTrigger extends Trig
 	private TimeZone timezone;
 
 	public EJBCronTrigger(ScheduleExpression expr) throws ParseException {
+	    
 		Map<Integer, String> fieldValues = new LinkedHashMap<Integer, String>();
 		fieldValues.put(Calendar.YEAR, expr.getYear());
 		fieldValues.put(Calendar.MONTH, expr.getMonth());
@@ -312,6 +313,9 @@ public class EJBCronTrigger extends Trig
 
 	@Override
 	public Date computeFirstFireTime(org.quartz.Calendar calendar) {
+	    
+	    log.debug("computeFirstFireTime starts, , current nextFireTime :"+nextFireTime);
+	    
 		// Copied from org.quartz.CronTrigger
         nextFireTime = getFireTimeAfter(new Date(getStartTime().getTime() - 1000l));
 
@@ -320,12 +324,15 @@ public class EJBCronTrigger extends Trig
             nextFireTime = getFireTimeAfter(nextFireTime);
         }
 		Logger.getInstance(LogCategory.TIMER, "org.apache.openejb.util.resources").debug("computeFirstFireTime [" + calendar + "] nextFireTime [" + nextFireTime + "]");
+		
+		log.debug("computeFirstFireTime completed, current nextFireTime :"+nextFireTime);
         return nextFireTime;
 	}
 
 	@Override
 	public int executionComplete(JobExecutionContext context,
 			JobExecutionException result) {
+	    log.debug("executionComplete");
 		// Copied from org.quartz.CronTrigger
         if (result != null && result.refireImmediately()) {
             return INSTRUCTION_RE_EXECUTE_JOB;
@@ -410,11 +417,15 @@ public class EJBCronTrigger extends Trig
                 return null; // The job will never be run
             }
 		}
+        
 		return calendar.after(stopCalendar) ? calendar.getTime() : null;
+		
+		
 	}
 
 	@Override
 	public Date getFireTimeAfter(Date afterTime) {
+	    log.debug("start to getFireTimeAfter:"+afterTime);
 		Calendar calendar = new GregorianCalendar(timezone);
         // calendar.setLenient(false);
 		calendar.setFirstDayOfWeek(Calendar.SUNDAY);
@@ -449,7 +460,7 @@ public class EJBCronTrigger extends Trig
                     resetFields(calendar, expr.field, false);
 
                     // If the weekday changed, the day of month changed too
-                    if (currentFieldIndex == 3) {
+                    if (expr.field == Calendar.DAY_OF_WEEK) {
                         currentFieldIndex--;
                     } else {
                         currentFieldIndex++;
@@ -469,6 +480,9 @@ public class EJBCronTrigger extends Trig
                 return null;
             }
         }
+		
+		log.debug("end of getFireTimeAfter, result is:"+ (calendar.before(stopCalendar) ? calendar.getTime() : null));
+		
 		return calendar.before(stopCalendar) ? calendar.getTime() : null;
 	}
 
@@ -543,11 +557,15 @@ public class EJBCronTrigger extends Trig
 	public void triggered(org.quartz.Calendar calendar) {
 		// Copied from org.quartz.CronTrigger
 		previousFireTime = nextFireTime;
+		
         nextFireTime = getFireTimeAfter(nextFireTime);
+        
+        
         while (nextFireTime != null && calendar != null
                 && !calendar.isTimeIncluded(nextFireTime.getTime())) {
             nextFireTime = getFireTimeAfter(nextFireTime);
         }
+        log.info("EJBCronTrigger is triggered by quartz scheduler");
 	}
 
 	@Override
@@ -563,6 +581,7 @@ public class EJBCronTrigger extends Trig
         } else {
             nextFireTime = new Date();
         }
+        
 	}
 
 	@Override
@@ -582,6 +601,7 @@ public class EJBCronTrigger extends Trig
                 }
             }
         }
+        
 	}
 
 	@Override
@@ -652,17 +672,10 @@ public class EJBCronTrigger extends Trig
 
 				if (field == Calendar.DAY_OF_WEEK) {
 					numValue++;
-					if (numValue == 8) {
-						numValue = 1;
-					}
 				} else if (field == Calendar.MONTH) {
 					numValue--; // Months are 0-based
 				}
 
-				// Validate the value
-				if (numValue < CALENDAR.getMinimum(field) || numValue > CALENDAR.getMaximum(field)) {
-					throw new ParseException(field, value, "Value is out of range");
-				}
 				return numValue;
 			}
 
@@ -686,6 +699,16 @@ public class EJBCronTrigger extends Trig
 		protected int convertValue(String value) throws ParseException {
 			return convertValue(value, field);
 		}
+		
+		protected boolean isValidResult(Calendar calendar, Integer result){
+		    
+		    if (result!=null && result>=calendar.getActualMinimum(field) && result <=calendar.getActualMaximum(field)){
+                return true;
+            } 
+		    
+		    return false;
+		    
+		}
 
 		/**
 		 * Returns the next allowed value in this calendar for the given
@@ -828,6 +851,34 @@ public class EJBCronTrigger extends Trig
                 endValue=convertValue(endWeekDay);
             }
             
+            
+            /*
+             * handle 0-7 for day of week range.
+             * 
+             * both 0 and 7 represent Sun.  We need to remove one from the range.
+             * 
+             */
+            if (field == Calendar.DAY_OF_WEEK) {
+                
+                if ((beginValue == 8 && endValue == 1)||(endValue == 8 && beginValue == 1)) {
+                    beginValue = 1;
+                    endValue = 7;
+                } else {
+                    
+                    
+                    if (beginValue == 8) {
+                        beginValue = 1;
+                    }
+
+                    if (endValue == 8) {
+                        endValue = 1;
+                    }           
+                }
+            }
+            
+            
+            
+            
             // Try converting a textual value to numeric
             if (endWeekDay.equals(LAST_IDENTIFIER)) {
                 start = -1;
@@ -872,15 +923,15 @@ public class EJBCronTrigger extends Trig
             int currValue = calendar.get(field);
             if (start2 != -1) {
                 if (currValue >= start2) {
-                    return currValue;
+                    return isValidResult(calendar,currValue)?currValue:null;
                 } else if (currValue > end) {
-                    return start2;
+                    return isValidResult(calendar,start2)?start2:null;
                 }
             }
             if (currValue <= start) {
-                return start;
+                return isValidResult(calendar,start)?start:null;
             } else if (currValue <= end) {
-                return currValue;
+                return isValidResult(calendar,currValue)?currValue:null;
             } else {
                 return null;
             }
@@ -901,15 +952,15 @@ public class EJBCronTrigger extends Trig
 		    int currValue = calendar.get(field);
             if (start2 != -1) {
                 if (currValue >= start2) {
-                    return currValue;
+                    return isValidResult(calendar,currValue)?currValue:null;
                 }
             }
             if (currValue <= start) {
                 return null;
             } else if (currValue <= end) {
-                return currValue;
+                return isValidResult(calendar,currValue)?currValue:null;
             } else {
-                return end;
+                return isValidResult(calendar,end)?end:null;
             }
 		}
 
@@ -992,6 +1043,11 @@ public class EJBCronTrigger extends Trig
                     
                 } else {
                     int individualValue = convertValue(value);
+                    
+                    if(field == Calendar.DAY_OF_WEEK && individualValue == 8){
+                        individualValue = 1;  
+                    }
+                    
                     values.add(individualValue);
                 }
             }
@@ -1035,7 +1091,9 @@ public class EJBCronTrigger extends Trig
 		    
 			int currValue = calendar.get(field);
 			
-			return newValues.ceiling(currValue);
+			Integer result = newValues.ceiling(currValue);
+			
+			return isValidResult(calendar, result)? result : null;
 			
 		}
 
@@ -1045,8 +1103,10 @@ public class EJBCronTrigger extends Trig
 		    TreeSet<Integer> newValues= getNewValuesFromDynamicExpressions(calendar);
 		    
 			int currValue = calendar.get(field);
+			
+			Integer result =newValues.floor(currValue);
             
-			return newValues.floor(currValue);
+			return isValidResult(calendar, result)? result : null;
 		}
 	}
 
@@ -1064,26 +1124,54 @@ public class EJBCronTrigger extends Trig
 
 		@Override
 		public Integer getNextValue(Calendar calendar) {
-			// Only applicable for seconds, minutes and hours so the actual maximum does not vary
-			// so currValue is always valid
-			int currValue = Math.max(calendar.get(field), start);
-			int maxValue = calendar.getMaximum(field);
-			if (currValue % interval > 0) {
-				int nextValue = currValue + (interval - currValue % interval);
-				return nextValue <= maxValue ? nextValue : null;
-			}
-			return currValue;
+		    
+            int currValue = calendar.get(field);
+
+            if (currValue > start) {
+
+                Integer nextValue = start + interval;
+
+                while (isValidResult(calendar, nextValue)) {
+
+                    if (nextValue >= currValue)
+                        return nextValue;
+
+                    nextValue = nextValue + interval;
+
+                }
+
+            } else {
+                return new Integer(start);
+            }
+
+            return null;
+		
 		}
 
 		@Override
 		public Integer getPreviousValue(Calendar calendar) {
-			// Only applicable for seconds, minutes and hours so the actual maximum does not vary
-			// so currValue is always valid
-			int maxValue = calendar.getMaximum(field);
-			int currValue = Math.min(calendar.get(field), maxValue);
-			int nextValue = currValue - currValue % interval;
-			return nextValue >= start ? nextValue : null;
-		}
+		    
+            int currValue = calendar.get(field);
+
+            if (currValue < start) {
+
+                Integer previousValue = start - interval;
+
+                while (isValidResult(calendar, previousValue)) {
+
+                    if (previousValue < currValue)
+                        return previousValue;
+
+                    previousValue = previousValue - interval;
+
+                }
+
+            } else {
+                return new Integer(start);
+            }
+
+            return null;
+        }
 
 	}
 
@@ -1102,7 +1190,9 @@ public class EJBCronTrigger extends Trig
 		public Integer getNextValue(Calendar calendar) {
 			int currDay = calendar.get(Calendar.DAY_OF_MONTH);
             Integer nthDay = getWeekdayInMonth(calendar);
-			return nthDay != null && nthDay >= currDay ? nthDay : null;
+			Integer result = nthDay != null && nthDay >= currDay ? nthDay : null;
+			
+			return isValidResult(calendar, result)? result : null;
 		}
         
         public Integer getWeekdayInMonth(Calendar calendar){
@@ -1115,12 +1205,14 @@ public class EJBCronTrigger extends Trig
 			// one we're looking for
 			int firstWeekday = (currDay % 7) - (currWeekday - weekday);
 			
+            firstWeekday = (firstWeekday == 0) ? 7 : firstWeekday;
+			
 			// Then calculate how many such weekdays there is in this month
-			int numWeekdays = (maxDay - firstWeekday) / 7;
+			int numWeekdays = firstWeekday>=0?(maxDay - firstWeekday) / 7 +1:(maxDay - firstWeekday) / 7;
 
 			// Then calculate the Nth of those days, or the last one if ordinal is null
 			int multiplier = ordinal != null ? ordinal : numWeekdays;
-			int nthDay = firstWeekday>0?(firstWeekday + (multiplier-1) * 7):(firstWeekday + multiplier * 7);
+			int nthDay = firstWeekday>=0?(firstWeekday + (multiplier-1) * 7):(firstWeekday + multiplier * 7);
 
 			// Return the calculated day, or null if the day is out of range
 			return nthDay <= maxDay ? nthDay : null;
@@ -1131,8 +1223,9 @@ public class EJBCronTrigger extends Trig
             
               int currDay = calendar.get(Calendar.DAY_OF_MONTH);
               Integer nthDay = getWeekdayInMonth(calendar);
-              return nthDay != null && nthDay <= currDay ? nthDay : null;
-        
+              Integer result = nthDay != null && nthDay <= currDay ? nthDay : null;
+              
+              return isValidResult(calendar, result)? result : null;
 		}
 
 	}
@@ -1156,13 +1249,15 @@ public class EJBCronTrigger extends Trig
 			int currValue = calendar.get(field);
 			int maxValue = calendar.getActualMaximum(field);
 			int value = maxValue - days;
-			return currValue <= value ? value : null;
+			Integer result = currValue <= value ? value : null;
+			return isValidResult(calendar, result)? result : null;
 		}
 
 		@Override
 		public Integer getPreviousValue(Calendar calendar) {
 			int maxValue = calendar.getActualMaximum(field);
-			return maxValue - days;
+			Integer result = maxValue - days;
+			return isValidResult(calendar, result)? result : null;
 		}
 
 	}

Modified: openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/timer/EJBCronTriggerTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/timer/EJBCronTriggerTest.java?rev=1101367&r1=1101366&r2=1101367&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/timer/EJBCronTriggerTest.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/timer/EJBCronTriggerTest.java Tue May 10 08:55:54 2011
@@ -31,6 +31,7 @@ import org.apache.openejb.core.timer.EJB
 import org.apache.openejb.core.timer.EJBCronTrigger.ParseException;
 import org.junit.Test;
 
+
 public class EJBCronTriggerTest {
 
 	@Test(timeout = 1000)
@@ -50,7 +51,7 @@ public class EJBCronTriggerTest {
 	}
 
 	@Test(timeout = 1000)
-	public void testWeekdays() throws ParseException {
+	public void testWeekdaysA() throws ParseException {
 		ScheduleExpression expr = new ScheduleExpression().year(2008).dayOfWeek("Wed").start(new Date(0));
 		EJBCronTrigger trigger = new EJBCronTrigger(expr);
 
@@ -65,10 +66,9 @@ public class EJBCronTriggerTest {
 		assertEquals(expectedTime, trigger.getFinalFireTime());
 	}
 	
-	
 
 	@Test(timeout = 1000)
-	public void testIncrements() throws ParseException {
+	public void testIncrementsA() throws ParseException {
 		ScheduleExpression expr = new ScheduleExpression().year(2008).month(1).dayOfMonth(20)
 				.dayOfWeek("sun").hour("6/3").minute(30).start(new Date(0));
 		EJBCronTrigger trigger = new EJBCronTrigger(expr);
@@ -90,6 +90,20 @@ public class EJBCronTriggerTest {
 		startTime = new Date(calendar.getTimeInMillis());
 		assertNull(trigger.getFireTimeAfter(startTime));
 	}
+	
+	@Test(timeout = 1000)
+    public void testIncrementsB() throws ParseException {
+        ScheduleExpression expr = new ScheduleExpression().year(2011).month(5).dayOfMonth(5).hour("23").minute("25/35").start(new Date(0));
+        EJBCronTrigger trigger = new EJBCronTrigger(expr);
+        assertEquals(new GregorianCalendar(2011, 4, 5, 23, 25, 0).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2011, 4, 5, 22, 0, 0).getTime()));
+    }
+	
+   @Test(timeout = 1000)
+    public void testIncrementsC() throws ParseException {
+        ScheduleExpression expr = new ScheduleExpression().year(2011).month(5).dayOfMonth(5).hour("*").minute("20/40").start(new GregorianCalendar(2011, 4, 5, 10, 21, 0).getTime());
+        EJBCronTrigger trigger = new EJBCronTrigger(expr);
+        assertEquals(new GregorianCalendar(2011, 4, 5, 11, 20, 0).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2011, 4, 5, 10, 21, 0).getTime()));
+    }
 
 	
 	@Test(timeout = 1000)
@@ -129,13 +143,20 @@ public class EJBCronTriggerTest {
     }
 
 	@Test(timeout = 5000)
-    public void testLastDayOfMonth() throws ParseException {
+    public void testLastDayOfMonthA() throws ParseException {
         ScheduleExpression expr = new ScheduleExpression().dayOfMonth("Last").hour(23).minute(59).second(59).start(new Date(0));
         EJBCronTrigger trigger = new EJBCronTrigger(expr);
         assertEquals(new GregorianCalendar(2009, 1, 28, 23, 59, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2009, 1, 1, 0, 0, 0).getTime()));
         //Test Leap year
         assertEquals(new GregorianCalendar(2000,1,29,23,59,59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2000, 1, 28, 0, 0, 0).getTime()));
     }
+	
+   @Test(timeout = 5000)
+    public void testLastDayOfMonthB() throws ParseException {
+        ScheduleExpression expr = new ScheduleExpression().year(2011).month(6).dayOfMonth("Last").hour(23).minute(59).second(59).start(new Date(0));
+        EJBCronTrigger trigger = new EJBCronTrigger(expr);
+        assertEquals(new GregorianCalendar(2011, 5, 30, 23, 59, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2011, 1, 1, 0, 0, 0).getTime()));
+    }
 
 	@Test(timeout = 5000)
     public void testMinusDayOfMonth() throws ParseException {
@@ -149,16 +170,91 @@ public class EJBCronTriggerTest {
     }
 
 	@Test(timeout = 5000)
-    public void testOrdinalNumbersDayOfMonth() throws ParseException {
+    public void testOrdinalNumbersDayOfMonthA() throws ParseException {
         ScheduleExpression expr = new ScheduleExpression().dayOfMonth("2nd mon").hour(23).minute(1).second(59).start(new Date(0));
         EJBCronTrigger trigger = new EJBCronTrigger(expr);
         assertEquals(new GregorianCalendar(2011, 4, 9, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2011, 4, 1, 0, 0, 0).getTime()));
         assertEquals(new GregorianCalendar(2011, 5, 13, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2011, 4, 10, 0, 0, 0).getTime()));
     }
-
+	
+	@Test(timeout = 5000)
+    public void testOrdinalNumbersDayOfMonthB() throws ParseException {
+        ScheduleExpression expr = new ScheduleExpression().dayOfMonth("last mon").hour(23).minute(1).second(59);
+        EJBCronTrigger trigger = new EJBCronTrigger(expr);
+        assertEquals(new GregorianCalendar(2100, 1, 22, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2100, 1, 1, 0, 0, 0).getTime()));
+    }
+	
+	@Test(timeout = 5000)
+    public void testOrdinalNumbersDayOfMonthC() throws ParseException {
+        ScheduleExpression expr = new ScheduleExpression().dayOfMonth("last sun").hour(23).minute(1).second(59);
+        EJBCronTrigger trigger = new EJBCronTrigger(expr);
+        assertEquals(new GregorianCalendar(2100, 1, 28, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2100, 1, 1, 0, 0, 0).getTime()));
+    }
+	
+	@Test(timeout = 5000)
+    public void testOrdinalNumbersDayOfMonthD() throws ParseException {
+        ScheduleExpression expr = new ScheduleExpression().dayOfMonth("1st sun").hour(23).minute(1).second(59);
+        EJBCronTrigger trigger = new EJBCronTrigger(expr);
+        assertEquals(new GregorianCalendar(2100, 1, 7, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2100, 1, 1, 0, 0, 0).getTime()));
+    }
+	
+   @Test(timeout = 5000)
+    public void testOrdinalNumbersDayOfMonthE() throws ParseException {
+        ScheduleExpression expr = new ScheduleExpression().dayOfMonth("5th Sun-Last Sun").hour(23).minute(1).second(59);
+        EJBCronTrigger trigger = new EJBCronTrigger(expr);
+        assertEquals(new GregorianCalendar(2100, 0, 31, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2100, 0, 1, 0, 0, 0).getTime()));
+    }
+   
+   
+   @Test(timeout = 500)
+   public void testSimpleDayOfWeek() throws ParseException {
+       ScheduleExpression expr = new ScheduleExpression().dayOfWeek("7").hour(23).minute(1).second(59).start(new Date(0));;
+       EJBCronTrigger trigger = new EJBCronTrigger(expr);
+       assertEquals(new GregorianCalendar(2011, 4, 8, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2011, 4, 5, 23, 1, 30).getTime()));
+   }
+   
+   @Test(timeout = 500)
+   public void testSimpleDayOfWeekA() throws ParseException {
+       ScheduleExpression expr = new ScheduleExpression().dayOfWeek("0").hour(23).minute(1).second(59).start(new Date(0));;
+       EJBCronTrigger trigger = new EJBCronTrigger(expr);
+       assertEquals(new GregorianCalendar(2011, 4, 8, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2011, 4, 5, 23, 1, 30).getTime()));
+   }
+   
+   @Test(timeout = 500)
+   public void testSimpleDayOfWeekB() throws ParseException {
+       ScheduleExpression expr = new ScheduleExpression().dayOfWeek("5").hour(14).minute(1).second(59).start(new Date(0));;
+       EJBCronTrigger trigger = new EJBCronTrigger(expr);
+       assertEquals(new GregorianCalendar(2011, 4, 6, 14, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2011, 4, 5, 23, 1, 30).getTime()));
+   }
+
+   
+   @Test(timeout = 5000)
+   public void testRangeYearsA() throws ParseException {
+       ScheduleExpression expr = new ScheduleExpression().year("2009-2013").month(2).dayOfMonth(29).hour(23).minute(1).second(0).start(new Date(0));;
+       EJBCronTrigger trigger = new EJBCronTrigger(expr);
+       assertEquals(new GregorianCalendar(2012, 1, 29, 23, 1,0).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2009, 1, 1, 23, 0, 0).getTime()));
+       
+   }
+   
+   @Test(timeout = 500)
+   public void testRangeYearsB() throws ParseException {
+       ScheduleExpression expr = new ScheduleExpression().year("2013-2016").month(2).dayOfMonth(29).hour(23).minute(1).second(0).start(new Date(0));;
+       EJBCronTrigger trigger = new EJBCronTrigger(expr);
+       assertEquals(new GregorianCalendar(2016, 1, 29, 23, 1,0).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2011, 1, 1, 23, 0, 0).getTime()));
+       
+   }
+   
+   @Test(timeout = 500)
+   public void testRangeMonthA() throws ParseException {
+       ScheduleExpression expr = new ScheduleExpression().year("2011").month("dec-dec").dayOfMonth(29).hour(23).minute(1).second(0).start(new Date(0));;
+       EJBCronTrigger trigger = new EJBCronTrigger(expr);
+       assertEquals(new GregorianCalendar(2011, 11, 29, 23, 1,0).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2009, 1, 1, 23, 0, 0).getTime()));
+       
+   }
+   
 
 	@Test(timeout = 5000)
-    public void testRangeADayOfMonth() throws ParseException {
+    public void testRangeDayOfMonthA() throws ParseException {
         ScheduleExpression expr = new ScheduleExpression().dayOfMonth("3-27").hour(23).minute(1).second(59).start(new Date(0));
         EJBCronTrigger trigger = new EJBCronTrigger(expr);
         assertEquals(new GregorianCalendar(2010, 6, 3, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 6, 1, 23, 0, 0).getTime()));
@@ -169,7 +265,7 @@ public class EJBCronTriggerTest {
     }
 
 	@Test(timeout = 5000)
-    public void testRangeBDayOfMonth() throws ParseException {
+    public void testRangeDayOfMonthB() throws ParseException {
         ScheduleExpression expr = new ScheduleExpression().dayOfMonth("27-3").hour(23).minute(1).second(59).start(new Date(0));
         EJBCronTrigger trigger = new EJBCronTrigger(expr);
         assertEquals(new GregorianCalendar(2010, 6, 1, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 6, 1, 23, 0, 0).getTime()));
@@ -180,7 +276,7 @@ public class EJBCronTriggerTest {
     }
 	
     @Test(timeout = 500)
-    public void testRangeCDayOfMonth() throws ParseException {
+    public void testRangeDayOfMonthC() throws ParseException {
         //7-27
         ScheduleExpression expr = new ScheduleExpression().dayOfMonth("1st Sat - 4th FRI").hour(23).minute(1).second(59).start(new Date(0));
         EJBCronTrigger trigger = new EJBCronTrigger(expr);
@@ -194,7 +290,7 @@ public class EJBCronTriggerTest {
 	
 
 	@Test(timeout = 500)
-    public void testRangeADayOfWeek() throws ParseException {
+    public void testRangeDayOfWeekA() throws ParseException {
         ScheduleExpression expr = new ScheduleExpression().dayOfWeek("tue-fri").hour(23).minute(1).second(59).start(new Date(0));
         EJBCronTrigger trigger = new EJBCronTrigger(expr);
         assertEquals(new GregorianCalendar(2010, 5, 29, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 5, 29, 23, 0, 0).getTime()));
@@ -205,7 +301,7 @@ public class EJBCronTriggerTest {
     }
 
 	@Test(timeout = 5000)
-    public void testRangeBDayOfWeek() throws ParseException {
+    public void testRangeDayOfWeekB() throws ParseException {
         ScheduleExpression expr = new ScheduleExpression().dayOfWeek("fri-tue").hour(23).minute(1).second(59).start(new Date(0));
         EJBCronTrigger trigger = new EJBCronTrigger(expr);
         assertEquals(new GregorianCalendar(2010, 5, 29, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 5, 29, 23, 0, 0).getTime()));
@@ -215,6 +311,20 @@ public class EJBCronTriggerTest {
         assertEquals(new GregorianCalendar(2010, 6, 2, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 6, 2, 23, 0, 0).getTime()));
         assertEquals(new GregorianCalendar(2010, 6, 3, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 6, 2, 23, 2, 0).getTime()));
     }
+	
+    @Test(timeout = 500)
+    public void testRangeCDayOfWeek() throws ParseException {
+        ScheduleExpression expr = new ScheduleExpression().dayOfWeek("0-7").hour(23).minute(1).second(59).start(new Date(0));
+        EJBCronTrigger trigger = new EJBCronTrigger(expr);
+        assertEquals(new GregorianCalendar(2010, 5, 29, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 5, 29, 23, 0, 0).getTime()));
+        assertEquals(new GregorianCalendar(2010, 5, 30, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 5, 29, 23, 2, 0).getTime()));
+        assertEquals(new GregorianCalendar(2010, 6, 1, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 6, 1, 23, 0, 0).getTime()));
+        assertEquals(new GregorianCalendar(2010, 6, 2, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 6, 1, 23, 3, 0).getTime()));
+        assertEquals(new GregorianCalendar(2010, 6, 2, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 6, 2, 23, 0, 0).getTime()));
+        assertEquals(new GregorianCalendar(2010, 6, 3, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 6, 2, 23, 2, 0).getTime()));
+    }	
+	
+	
 
 	@Test(timeout = 5000)
     public void testListDayOfMonth() throws ParseException {
@@ -281,7 +391,7 @@ public class EJBCronTriggerTest {
     }
 
 	@Test(timeout = 5000)
-    public void testListDayOfWeek() throws ParseException {
+    public void testListDayOfWeekA() throws ParseException {
         String[] dayOfWeeks = { "tue,wed,thu,fri", "wed,tue,thu,fri", "tue,wed,thu,fri,tue" };
         for (String dayOfWeek : dayOfWeeks) {
             ScheduleExpression expr = new ScheduleExpression().dayOfWeek(dayOfWeek).hour(23).minute(1).second(59).start(new Date(0));
@@ -293,6 +403,22 @@ public class EJBCronTriggerTest {
             assertEquals(new GregorianCalendar(2010, 6, 6, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 6, 2, 23, 2, 0).getTime()));
         }
     }
+	
+   @Test(timeout = 5000)
+    public void testListDayOfWeekB() throws ParseException {
+        String[] dayOfWeeks = { "2,3,4,5", "3,2,4,5", "2,3,4,5,2" };
+        for (String dayOfWeek : dayOfWeeks) {
+            ScheduleExpression expr = new ScheduleExpression().dayOfWeek(dayOfWeek).hour(23).minute(1).second(59).start(new Date(0));
+            EJBCronTrigger trigger = new EJBCronTrigger(expr);
+            assertEquals(new GregorianCalendar(2010, 5, 29, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 5, 29, 23, 0, 0).getTime()));
+            assertEquals(new GregorianCalendar(2010, 5, 30, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 5, 29, 23, 2, 0).getTime()));
+            assertEquals(new GregorianCalendar(2010, 6, 1, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 6, 1, 23, 0, 0).getTime()));
+            assertEquals(new GregorianCalendar(2010, 6, 2, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 6, 1, 23, 3, 0).getTime()));
+            assertEquals(new GregorianCalendar(2010, 6, 6, 23, 1, 59).getTime(), trigger.getFireTimeAfter(new GregorianCalendar(2010, 6, 2, 23, 2, 0).getTime()));
+        }
+    }
+   
+   
 
 	@Test(timeout = 5000)
     public void testCompoundListDayOfWeek() throws ParseException {