示例#1
0
bool
Programme::isActive(Clock &clock)
{
	// Calculate the time limits in seconds
	unsigned long startTimeSec = ((unsigned long)startTime)
	                             * TIME_CONVERSION_RATIO;
	unsigned long endTimeSec = ((unsigned long)endTime)
	                            * TIME_CONVERSION_RATIO;
	
	if (isWeekday()) {
		// Weekday programme
		return ((getWeekdays() & (0x01 << clock.getDayOfWeek())) != 0)
		       && clock.getSecsToday() >= startTimeSec
		       && clock.getSecsToday() < endTimeSec;
	} else {
		// Non-Weekday programme
		uint8_t dayNumber = clock.getDayNumber();
		unsigned long secsToday = clock.getSecsToday();
		
		return (dayNumber == startDayNumber    && startDayNumber == endDayNumber
		        && secsToday >= startTimeSec && secsToday < endTimeSec)
		       || (dayNumber == startDayNumber && startDayNumber != endDayNumber
		           && secsToday >= startTimeSec)
		       || (dayNumber == endDayNumber   && startDayNumber != endDayNumber
		           && secsToday < startTimeSec)
		       || (dayNumber > startDayNumber  && startDayNumber != endDayNumber
		           && dayNumber < endDayNumber);
	}
}
示例#2
0
bool
Programme::isExpired(Clock &clock)
{
	if (isWeekday()) {
		return false;
	} else {
		uint8_t dayNumber = clock.getDayNumber();
		return (dayNumber > endDayNumber)
		       || (dayNumber == endDayNumber
		           && !isActive(clock));
	}
}