use of de.avanux.smartapplianceenabler.schedule.TimeframeInterval in project SmartApplianceEnabler by camueller.
the class ConsecutiveDaysTimeframe method getIntervals.
public List<TimeframeInterval> getIntervals(LocalDateTime now) {
if (start != null && end != null) {
LocalDateTime earliestStartNextOccurrence = start.toNextOccurrence(now);
LocalDateTime latestEndNextOccurrence = end.toNextOccurrence(now);
LocalDateTime earliestStartDateTime = earliestStartNextOccurrence;
if (latestEndNextOccurrence.isBefore(earliestStartNextOccurrence) && now.isBefore(latestEndNextOccurrence)) {
earliestStartDateTime = start.toLastOccurrence(now);
}
LocalDateTime latestEndDateTime = end.toNextOccurrence(earliestStartDateTime);
Interval interval = new Interval(earliestStartDateTime.toDateTime(), latestEndDateTime.toDateTime()).withChronology(ISOChronology.getInstance());
TimeframeInterval timeframeInterval = new TimeframeInterval(this, interval);
return Collections.singletonList(timeframeInterval);
}
return null;
}
use of de.avanux.smartapplianceenabler.schedule.TimeframeInterval in project SmartApplianceEnabler by camueller.
the class ApplianceTest method getRuntimeRequest_TimeFrameAlreadyStartedAndActive_Sufficient.
@Test
public void getRuntimeRequest_TimeFrameAlreadyStartedAndActive_Sufficient() {
int nowSeconds = 10;
LocalDateTime now = toToday(8, 0, nowSeconds);
Schedule schedule = new Schedule(3600, null, new TimeOfDay(8, 0, 0), new TimeOfDay(12, 0, 0));
TimeframeInterval activeTimeframeInterval = schedule.getTimeframe().getIntervals(now).get(0);
List<RuntimeRequest> runtimeRequests = this.appliance.getRuntimeRequests(now, Collections.singletonList(schedule), activeTimeframeInterval, true, 3600 - nowSeconds, null);
Assert.assertEquals(3, runtimeRequests.size());
Assert.assertEquals(new RuntimeRequest(0, 14400 - nowSeconds, 3600 - nowSeconds, null), runtimeRequests.get(0));
Assert.assertEquals(new RuntimeRequest(86400 - nowSeconds, 100800 - nowSeconds, 3600, null), runtimeRequests.get(1));
Assert.assertEquals(new RuntimeRequest(172800 - nowSeconds, 187200 - nowSeconds, 3600, null), runtimeRequests.get(2));
}
use of de.avanux.smartapplianceenabler.schedule.TimeframeInterval in project SmartApplianceEnabler by camueller.
the class ConsecutiveDaysTimeframeTest method getIntervals_AcrossWeeks_WithinInterval.
@Test
public void getIntervals_AcrossWeeks_WithinInterval() {
TimeOfDayOfWeek startTimeOfDayOfWeek = new TimeOfDayOfWeek(6, 15, 0, 0);
TimeOfDayOfWeek endTimeOfDayOfWeek = new TimeOfDayOfWeek(1, 20, 0, 0);
ConsecutiveDaysTimeframe timeRange = new ConsecutiveDaysTimeframe(startTimeOfDayOfWeek, endTimeOfDayOfWeek);
LocalDateTime now = toDayOfWeek(7, 10, 0, 0);
List<TimeframeInterval> intervals = timeRange.getIntervals(now);
Assert.assertEquals(1, intervals.size());
LocalDateTime start = startTimeOfDayOfWeek.toLastOccurrence(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 ConsecutiveDaysTimeframeTest method getIntervals_AcrossWeeks_BeforeIntervalStart.
@Test
public void getIntervals_AcrossWeeks_BeforeIntervalStart() {
TimeOfDayOfWeek startTimeOfDayOfWeek = new TimeOfDayOfWeek(6, 15, 0, 0);
TimeOfDayOfWeek endTimeOfDayOfWeek = new TimeOfDayOfWeek(1, 20, 0, 0);
ConsecutiveDaysTimeframe timeRange = new ConsecutiveDaysTimeframe(startTimeOfDayOfWeek, endTimeOfDayOfWeek);
LocalDateTime now = toDayOfWeek(3, 0, 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 ConsecutiveDaysTimeframeTest method getIntervals_SameWeek_BeforeIntervalStart.
@Test
public void getIntervals_SameWeek_BeforeIntervalStart() {
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(1, 0, 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());
}
Aggregations