1 package org.jbpm.calendar; 2 3 import java.io.Serializable ; 4 import java.text.*; 5 import java.util.*; 6 import java.util.List ; 7 import java.util.Properties ; 8 9 12 public class Holiday implements Serializable { 13 14 private static final long serialVersionUID = 1L; 15 16 Date fromDay = null; 17 Date toDay = null; 18 BusinessCalendar businessCalendar = null; 19 20 public static List parseHolidays(Properties calendarProperties, BusinessCalendar businessCalendar) { 21 List holidays = new ArrayList(); 22 23 DateFormat dateFormat = new SimpleDateFormat(calendarProperties.getProperty("day.format")); 24 Iterator iter = calendarProperties.keySet().iterator(); 25 while (iter.hasNext()) { 26 String key = (String ) iter.next(); 27 if (key.startsWith("holiday")) { 28 Holiday holiday = new Holiday(calendarProperties.getProperty(key), dateFormat, businessCalendar); 29 holidays.add(holiday); 30 } 31 } 32 33 return holidays; 34 } 35 36 public Holiday(String holidayText, DateFormat dateFormat, BusinessCalendar businessCalendar) { 37 this.businessCalendar = businessCalendar; 38 try { 39 int separatorIndex = holidayText.indexOf('-'); 40 if (separatorIndex==-1) { 41 fromDay = dateFormat.parse(holidayText.trim()); 42 toDay = fromDay; 43 } else { 44 String fromText = holidayText.substring(0, separatorIndex).trim(); 45 String toText = holidayText.substring(separatorIndex+1).trim(); 46 fromDay = dateFormat.parse(fromText); 47 toDay = dateFormat.parse(toText); 48 } 49 Calendar calendar = BusinessCalendar.getCalendar(); 52 calendar.setTime(toDay); 53 calendar.add(Calendar.DATE, 1); 54 toDay = calendar.getTime(); 55 56 } catch (ParseException e) { 57 throw new RuntimeException ("couldn't parse holiday '"+holidayText+"'", e); 58 } 59 } 60 61 public boolean includes(Date date) { 62 return ( (fromDay.getTime()<=date.getTime()) 63 && (date.getTime()<toDay.getTime()) 64 ); 65 } 66 } 67 | Popular Tags |