use of de.avanux.smartapplianceenabler.schedule.TimeframeInterval in project SmartApplianceEnabler by camueller.
the class DayTimeframeTest method getIntervals_AllDayOfWeek_BeforeIntervalStart.
@Test
public void getIntervals_AllDayOfWeek_BeforeIntervalStart() {
DayTimeframe timeframe = new DayTimeframe(new TimeOfDay(10, 0, 0), new TimeOfDay(12, 0, 0));
List<TimeframeInterval> intervals = timeframe.getIntervals(toToday(9, 0, 0));
Assert.assertEquals(7, intervals.size());
Assert.assertEquals(new Interval(toToday(10, 0, 0).toDateTime(), toToday(12, 0, 0).toDateTime()), intervals.get(0).getInterval());
Assert.assertEquals(new Interval(toDay(1, 10, 0, 0).toDateTime(), toDay(1, 12, 0, 0).toDateTime()), intervals.get(1).getInterval());
Assert.assertEquals(new Interval(toDay(2, 10, 0, 0).toDateTime(), toDay(2, 12, 0, 0).toDateTime()), intervals.get(2).getInterval());
Assert.assertEquals(new Interval(toDay(3, 10, 0, 0).toDateTime(), toDay(3, 12, 0, 0).toDateTime()), intervals.get(3).getInterval());
Assert.assertEquals(new Interval(toDay(4, 10, 0, 0).toDateTime(), toDay(4, 12, 0, 0).toDateTime()), intervals.get(4).getInterval());
Assert.assertEquals(new Interval(toDay(5, 10, 0, 0).toDateTime(), toDay(5, 12, 0, 0).toDateTime()), intervals.get(5).getInterval());
Assert.assertEquals(new Interval(toDay(6, 10, 0, 0).toDateTime(), toDay(6, 12, 0, 0).toDateTime()), intervals.get(6).getInterval());
}
use of de.avanux.smartapplianceenabler.schedule.TimeframeInterval in project SmartApplianceEnabler by camueller.
the class DayTimeframeTest method getIntervals_ValidOnlyOnHoliday_HolidaySet.
@Test
public void getIntervals_ValidOnlyOnHoliday_HolidaySet() {
DayTimeframe timeframe = new DayTimeframe(new TimeOfDay(10, 0, 0), new TimeOfDay(12, 0, 0), Collections.singletonList(8));
LocalDateTime now = toDayOfWeek(1, 9, 0, 0);
timeframe.setHolidays(Collections.singletonList(now.toLocalDate()));
List<TimeframeInterval> intervals = timeframe.getIntervals(now);
Assert.assertEquals(1, intervals.size());
Assert.assertEquals(new Interval(toDayOfWeek(now, 1, 10, 0, 0).toDateTime(), toDayOfWeek(now, 1, 12, 0, 0).toDateTime()), intervals.get(0).getInterval());
}
use of de.avanux.smartapplianceenabler.schedule.TimeframeInterval in project SmartApplianceEnabler by camueller.
the class DayTimeframeTest method getIntervals_DayOfWeekNotMatching_WithinInterval.
@Test
public void getIntervals_DayOfWeekNotMatching_WithinInterval() {
DayTimeframe timeframe = new DayTimeframe(new TimeOfDay(10, 0, 0), new TimeOfDay(12, 0, 0), Collections.singletonList(3));
LocalDateTime now = toDayOfWeek(3, 11, 0, 0);
List<TimeframeInterval> intervals = timeframe.getIntervals(now);
Assert.assertEquals(1, intervals.size());
Assert.assertEquals(new Interval(toDayOfWeek(now, 3, 10, 0, 0).toDateTime(), toDayOfWeek(now, 3, 12, 0, 0).toDateTime()), intervals.get(0).getInterval());
}
use of de.avanux.smartapplianceenabler.schedule.TimeframeInterval in project SmartApplianceEnabler by camueller.
the class ConsecutiveDaysTimeframeTest method getIntervals_SameWeek_AfterInterval.
@Test
public void getIntervals_SameWeek_AfterInterval() {
TimeOfDayOfWeek startTimeOfDayOfWeek = new TimeOfDayOfWeek(5, 15, 0, 0);
TimeOfDayOfWeek endTimeOfDayOfWeek = new TimeOfDayOfWeek(7, 20, 0, 0);
ConsecutiveDaysTimeframe timeRange = new ConsecutiveDaysTimeframe(startTimeOfDayOfWeek, endTimeOfDayOfWeek);
LocalDateTime now = toDayOfWeek(7, 21, 0, 0);
List<TimeframeInterval> intervals = timeRange.getIntervals(now);
Assert.assertEquals(1, intervals.size());
LocalDateTime start = startTimeOfDayOfWeek.toNextOccurrence(now);
assertDateTime(start, intervals.get(0).getInterval().getStart().toLocalDateTime());
assertDateTime(endTimeOfDayOfWeek.toNextOccurrence(start), intervals.get(0).getInterval().getEnd().toLocalDateTime());
}
use of de.avanux.smartapplianceenabler.schedule.TimeframeInterval in project SmartApplianceEnabler by camueller.
the class RunningTimeMonitor method activateTimeframeInterval.
/**
* Activate the current or next timeframe interval from one of the given schedules.
* @param now
* @param schedules
*/
public void activateTimeframeInterval(LocalDateTime now, List<Schedule> schedules) {
if (activeTimeframeInterval == null && schedules != null && schedules.size() > 0) {
TimeframeInterval nextSufficientTimeframeInterval = Schedule.getCurrentOrNextTimeframeInterval(now, schedules, true, false);
activateTimeframeInterval(now, nextSufficientTimeframeInterval);
}
}
Aggregations