Search in sources :

Example 1 with TimeframeInterval

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;
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) TimeframeInterval(de.avanux.smartapplianceenabler.schedule.TimeframeInterval) Interval(org.joda.time.Interval) TimeframeInterval(de.avanux.smartapplianceenabler.schedule.TimeframeInterval)

Example 2 with TimeframeInterval

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));
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) TimeOfDay(de.avanux.smartapplianceenabler.schedule.TimeOfDay) TimeframeInterval(de.avanux.smartapplianceenabler.schedule.TimeframeInterval) Schedule(de.avanux.smartapplianceenabler.schedule.Schedule) Test(org.junit.Test)

Example 3 with TimeframeInterval

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());
}
Also used : TimeOfDayOfWeek(de.avanux.smartapplianceenabler.schedule.TimeOfDayOfWeek) LocalDateTime(org.joda.time.LocalDateTime) TimeframeInterval(de.avanux.smartapplianceenabler.schedule.TimeframeInterval) ConsecutiveDaysTimeframe(de.avanux.smartapplianceenabler.schedule.ConsecutiveDaysTimeframe) Test(org.junit.Test)

Example 4 with TimeframeInterval

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());
}
Also used : TimeOfDayOfWeek(de.avanux.smartapplianceenabler.schedule.TimeOfDayOfWeek) LocalDateTime(org.joda.time.LocalDateTime) TimeframeInterval(de.avanux.smartapplianceenabler.schedule.TimeframeInterval) ConsecutiveDaysTimeframe(de.avanux.smartapplianceenabler.schedule.ConsecutiveDaysTimeframe) Test(org.junit.Test)

Example 5 with TimeframeInterval

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());
}
Also used : TimeOfDayOfWeek(de.avanux.smartapplianceenabler.schedule.TimeOfDayOfWeek) LocalDateTime(org.joda.time.LocalDateTime) TimeframeInterval(de.avanux.smartapplianceenabler.schedule.TimeframeInterval) ConsecutiveDaysTimeframe(de.avanux.smartapplianceenabler.schedule.ConsecutiveDaysTimeframe) Test(org.junit.Test)

Aggregations

TimeframeInterval (de.avanux.smartapplianceenabler.schedule.TimeframeInterval)22 Test (org.junit.Test)17 LocalDateTime (org.joda.time.LocalDateTime)16 TimeOfDay (de.avanux.smartapplianceenabler.schedule.TimeOfDay)12 Interval (org.joda.time.Interval)10 DayTimeframe (de.avanux.smartapplianceenabler.schedule.DayTimeframe)9 ConsecutiveDaysTimeframe (de.avanux.smartapplianceenabler.schedule.ConsecutiveDaysTimeframe)6 TimeOfDayOfWeek (de.avanux.smartapplianceenabler.schedule.TimeOfDayOfWeek)6 Schedule (de.avanux.smartapplianceenabler.schedule.Schedule)4 Timeframe (de.avanux.smartapplianceenabler.schedule.Timeframe)1