1 37 package net.sourceforge.cruisecontrol; 38 39 import java.util.Calendar ; 40 import java.util.Date ; 41 42 import net.sourceforge.cruisecontrol.util.DateUtil; 43 import net.sourceforge.cruisecontrol.util.PerDayScheduleItem; 44 import net.sourceforge.cruisecontrol.util.ValidationHelper; 45 46 53 public class PauseBuilder extends PerDayScheduleItem { 54 55 private int startTime = PerDayScheduleItem.NOT_SET; 56 private int endTime = PerDayScheduleItem.NOT_SET; 57 58 public void validate() throws CruiseControlException { 59 ValidationHelper.assertFalse(startTime < 0, 60 "'starttime' is a required attribute on PauseBuilder"); 61 62 ValidationHelper.assertFalse(endTime < 0, 63 "'endtime' is a required attribute on PauseBuilder"); 64 65 ValidationHelper.assertFalse(getDay() == INVALID_NAME_OF_DAY, 66 "setDay attribute on PauseBuilder requires english name for day of week (case insensitive)"); 67 } 68 69 public void setStartTime(int time) { 70 startTime = time; 71 } 72 73 public void setEndTime(int time) { 74 endTime = time; 75 } 76 77 public int getStartTime() { 78 return startTime; 79 } 80 81 public int getEndTime() { 82 return endTime; 83 } 84 85 92 public boolean isPaused(Date date) { 93 Calendar now = Calendar.getInstance(); 94 now.setTime(date); 95 int currentDay = now.get(Calendar.DAY_OF_WEEK); 96 int currentTime = DateUtil.getTimeFromDate(date); 97 98 int builderDay = getDay(); 99 boolean isValidDay = ((builderDay < 0) || (builderDay == currentDay)); 100 101 if (startTime < endTime) { 102 return ( 103 startTime <= currentTime 104 && currentTime <= endTime 105 && isValidDay); 106 } 107 108 return ( 109 (startTime <= currentTime && (builderDay < 0 || builderDay == currentDay)) 110 || (currentTime <= endTime 111 && (builderDay < 0 || builderDay == (currentDay - 1)))); 112 } 113 114 } 115 | Popular Tags |