1 17 18 22 23 package org.quartz.impl.calendar; 24 25 import java.io.Serializable ; 26 import java.util.TimeZone ; 27 28 import org.quartz.Calendar; 29 30 42 public class WeeklyCalendar extends BaseCalendar implements Calendar, 43 Serializable { 44 static final long serialVersionUID = -6809298821229007586L; 45 46 private boolean[] excludeDays = new boolean[8]; 49 50 private boolean excludeAll = false; 52 53 public WeeklyCalendar() { 54 this(null, null); 55 } 56 57 public WeeklyCalendar(Calendar baseCalendar) { 58 this(baseCalendar, null); 59 } 60 61 public WeeklyCalendar(TimeZone timeZone) { 62 super(null, timeZone); 63 } 64 65 public WeeklyCalendar(Calendar baseCalendar, TimeZone timeZone) { 66 super(baseCalendar, timeZone); 67 68 excludeDays[java.util.Calendar.SUNDAY] = true; 69 excludeDays[java.util.Calendar.SATURDAY] = true; 70 excludeAll = areAllDaysExcluded(); 71 } 72 73 78 public boolean[] getDaysExcluded() { 79 return excludeDays; 80 } 81 82 88 public boolean isDayExcluded(int wday) { 89 return excludeDays[wday]; 90 } 91 92 99 public void setDaysExcluded(boolean[] weekDays) { 100 if (weekDays == null) { 101 return; 102 } 103 104 excludeDays = weekDays; 105 excludeAll = areAllDaysExcluded(); 106 } 107 108 115 public void setDayExcluded(int wday, boolean exclude) { 116 excludeDays[wday] = exclude; 117 excludeAll = areAllDaysExcluded(); 118 } 119 120 127 public boolean areAllDaysExcluded() { 128 return 129 isDayExcluded(java.util.Calendar.SUNDAY) && 130 isDayExcluded(java.util.Calendar.MONDAY) && 131 isDayExcluded(java.util.Calendar.TUESDAY) && 132 isDayExcluded(java.util.Calendar.WEDNESDAY) && 133 isDayExcluded(java.util.Calendar.THURSDAY) && 134 isDayExcluded(java.util.Calendar.FRIDAY) && 135 isDayExcluded(java.util.Calendar.SATURDAY); 136 } 137 138 148 public boolean isTimeIncluded(long timeStamp) { 149 if (excludeAll == true) { 150 return false; 151 } 152 153 if (super.isTimeIncluded(timeStamp) == false) { return false; } 156 157 java.util.Calendar cl = createJavaCalendar(timeStamp); 158 int wday = cl.get(java.util.Calendar.DAY_OF_WEEK); 159 160 return !(isDayExcluded(wday)); 161 } 162 163 174 public long getNextIncludedTime(long timeStamp) { 175 if (excludeAll == true) { 176 return 0; 177 } 178 179 long baseTime = super.getNextIncludedTime(timeStamp); 181 if ((baseTime > 0) && (baseTime > timeStamp)) { 182 timeStamp = baseTime; 183 } 184 185 java.util.Calendar cl = getStartOfDayJavaCalendar(timeStamp); 187 int wday = cl.get(java.util.Calendar.DAY_OF_WEEK); 188 189 if (!isDayExcluded(wday)) { 190 return timeStamp; } 192 193 while (isDayExcluded(wday) == true) { 194 cl.add(java.util.Calendar.DATE, 1); 195 wday = cl.get(java.util.Calendar.DAY_OF_WEEK); 196 } 197 198 return cl.getTime().getTime(); 199 } 200 } 201 | Popular Tags |