1 17 18 22 23 package org.quartz.impl.calendar; 24 25 import java.io.Serializable ; 26 import java.util.Date ; 27 import java.util.TimeZone ; 28 29 import org.quartz.Calendar; 30 31 51 public class BaseCalendar implements Calendar, Serializable { 52 53 static final long serialVersionUID = 3106623404629760239L; 54 55 private Calendar baseCalendar; 57 58 private String description; 59 60 private TimeZone timeZone; 61 62 public BaseCalendar() { 63 } 64 65 public BaseCalendar(Calendar baseCalendar) { 66 setBaseCalendar(baseCalendar); 67 } 68 69 73 public BaseCalendar(TimeZone timeZone) { 74 setTimeZone(timeZone); 75 } 76 77 81 public BaseCalendar(Calendar baseCalendar, TimeZone timeZone) { 82 setBaseCalendar(baseCalendar); 83 setTimeZone(timeZone); 84 } 85 86 91 public void setBaseCalendar(Calendar baseCalendar) { 92 this.baseCalendar = baseCalendar; 93 } 94 95 100 public Calendar getBaseCalendar() { 101 return this.baseCalendar; 102 } 103 104 112 public String getDescription() { 113 return description; 114 } 115 116 123 public void setDescription(String description) { 124 this.description = description; 125 } 126 127 134 public TimeZone getTimeZone() { 135 return timeZone; 136 } 137 138 144 public void setTimeZone(TimeZone timeZone) { 145 this.timeZone = timeZone; 146 } 147 148 157 public boolean isTimeIncluded(long timeStamp) { 158 159 if (timeStamp <= 0) { 160 throw new IllegalArgumentException ( 161 "timeStamp must be greater 0"); 162 } 163 164 if (baseCalendar != null) { 165 if (baseCalendar.isTimeIncluded(timeStamp) == false) { return false; } 166 } 167 168 return true; 169 } 170 171 180 public long getNextIncludedTime(long timeStamp) { 181 182 if (timeStamp <= 0) { 183 throw new IllegalArgumentException ( 184 "timeStamp must be greater 0"); 185 } 186 187 if (baseCalendar != null) { 188 return baseCalendar.getNextIncludedTime(timeStamp); 189 } 190 191 return timeStamp; 192 } 193 194 200 public static Date buildHoliday(Date excludedDate) { 201 return new BaseCalendar().getStartOfDayJavaCalendar(excludedDate.getTime()).getTime(); 202 } 203 204 210 public static long buildHoliday(long timeStamp) { 211 return new BaseCalendar().getStartOfDayJavaCalendar(timeStamp).getTime().getTime(); 212 } 213 214 219 public static java.util.Calendar getJavaCalendar(long timeStamp) { 220 return new BaseCalendar().createJavaCalendar(timeStamp); 221 } 222 223 228 protected java.util.Calendar createJavaCalendar(long timeStamp) { 229 java.util.Calendar calendar = createJavaCalendar(); 230 calendar.setTime(new Date (timeStamp)); 231 return calendar; 232 } 233 234 239 protected java.util.Calendar createJavaCalendar() { 240 return 241 (getTimeZone() == null) ? 242 java.util.Calendar.getInstance() : 243 java.util.Calendar.getInstance(getTimeZone()); 244 } 245 246 256 protected java.util.Calendar getStartOfDayJavaCalendar(long timeInMillis) { 257 java.util.Calendar startOfDay = createJavaCalendar(timeInMillis); 258 startOfDay.set(java.util.Calendar.HOUR_OF_DAY, 0); 259 startOfDay.set(java.util.Calendar.MINUTE, 0); 260 startOfDay.set(java.util.Calendar.SECOND, 0); 261 startOfDay.set(java.util.Calendar.MILLISECOND, 0); 262 return startOfDay; 263 } 264 265 275 protected java.util.Calendar getEndOfDayJavaCalendar(long timeInMillis) { 276 java.util.Calendar endOfDay = createJavaCalendar(timeInMillis); 277 endOfDay.set(java.util.Calendar.HOUR_OF_DAY, 23); 278 endOfDay.set(java.util.Calendar.MINUTE, 59); 279 endOfDay.set(java.util.Calendar.SECOND, 59); 280 endOfDay.set(java.util.Calendar.MILLISECOND, 999); 281 return endOfDay; 282 } 283 } 284 | Popular Tags |