Search in sources :

Example 16 with LocalDateTime

use of org.joda.time.LocalDateTime in project SmartApplianceEnabler by camueller.

the class SempController method createSempTimeFrame.

protected de.avanux.smartapplianceenabler.semp.webservice.Timeframe createSempTimeFrame(ApplianceLogger applianceLogger, String deviceId, Schedule schedule, Interval interval, long minRunningTime, long maxRunningTime, LocalDateTime now) {
    Long earliestStart = 0l;
    DateTime start = interval.getStart();
    DateTime end = interval.getEnd();
    if (start.isAfter(now.toDateTime())) {
        earliestStart = Double.valueOf(new Interval(now.toDateTime(), start).toDurationMillis() / 1000).longValue();
    }
    LocalDateTime nowBeforeEnd = new LocalDateTime(now);
    if (now.toDateTime().isAfter(end)) {
        nowBeforeEnd = now.minusHours(24);
    }
    Long latestEnd = Double.valueOf(new Interval(nowBeforeEnd.toDateTime(), end).toDurationMillis() / 1000).longValue();
    return createSempTimeFrame(applianceLogger, deviceId, earliestStart, latestEnd, minRunningTime, maxRunningTime);
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) DateTime(org.joda.time.DateTime) LocalDateTime(org.joda.time.LocalDateTime) Interval(org.joda.time.Interval)

Example 17 with LocalDateTime

use of org.joda.time.LocalDateTime in project SmartApplianceEnabler by camueller.

the class ConsecutiveDaysTimeframeTest method getIntervals_SameWeek_WithinInterval.

@Test
public void getIntervals_SameWeek_WithinInterval() {
    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(5, 18, 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 : LocalDateTime(org.joda.time.LocalDateTime) Test(org.junit.Test)

Example 18 with LocalDateTime

use of org.joda.time.LocalDateTime in project SmartApplianceEnabler by camueller.

the class ScheduleTest method getNextSufficientTimeframe_timeFrameNotValidForDow.

@Test
public void getNextSufficientTimeframe_timeFrameNotValidForDow() {
    LocalDateTime now = toToday(9, 0, 0);
    List<Schedule> schedules = new ArrayList<Schedule>();
    // Timeframe only valid yesterday
    schedules.add(new Schedule(7200, 7200, new TimeOfDay(10, 0, 0), new TimeOfDay(14, 0, 0), Collections.singletonList(now.minusDays(1).get(DateTimeFieldType.dayOfWeek()))));
    // Timeframe only valid tomorrow
    schedules.add(new Schedule(7200, 7200, new TimeOfDay(15, 0, 0), new TimeOfDay(18, 0, 0), Collections.singletonList(now.plusDays(1).get(DateTimeFieldType.dayOfWeek()))));
    Interval expectedInterval = new Interval(toDay(1, 15, 0, 0).toDateTime(), toDay(1, 18, 0, 0).toDateTime());
    Assert.assertEquals(expectedInterval, Schedule.getCurrentOrNextTimeframeInterval(now, schedules, false, false).getInterval());
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) ArrayList(java.util.ArrayList) Interval(org.joda.time.Interval) Test(org.junit.Test)

Example 19 with LocalDateTime

use of org.joda.time.LocalDateTime in project SmartApplianceEnabler by camueller.

the class SempControllerTest method createSempTimeFrame.

@Test
public void createSempTimeFrame() {
    ApplianceLogger logger = new ApplianceLogger(LoggerFactory.getLogger(Appliance.class));
    logger.setApplianceId(DEVICE_ID);
    LocalDateTime now = toToday(0, 30, 0);
    Schedule schedule = new Schedule(7200, 7200, new TimeOfDay(1, 0, 0), new TimeOfDay(9, 0, 0));
    Interval interval = schedule.getTimeframe().getIntervals(now).get(0).getInterval();
    de.avanux.smartapplianceenabler.semp.webservice.Timeframe sempTimeFrame = sempController.createSempTimeFrame(logger, DEVICE_ID, schedule, interval, 0, 0, now);
    Assert.assertEquals(1800, (long) sempTimeFrame.getEarliestStart());
    Assert.assertEquals(30600, (long) sempTimeFrame.getLatestEnd());
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) ApplianceLogger(de.avanux.smartapplianceenabler.log.ApplianceLogger) Interval(org.joda.time.Interval) Test(org.junit.Test)

Example 20 with LocalDateTime

use of org.joda.time.LocalDateTime in project SmartApplianceEnabler by camueller.

the class SempControllerTest method createSempTimeFrame_TimeFrameOverMidnight_BeforeMidnight.

@Test
public void createSempTimeFrame_TimeFrameOverMidnight_BeforeMidnight() {
    ApplianceLogger logger = new ApplianceLogger(LoggerFactory.getLogger(Appliance.class));
    logger.setApplianceId(DEVICE_ID);
    LocalDateTime now = toToday(23, 30, 0);
    Schedule schedule = new Schedule(7200, 7200, new TimeOfDay(20, 0, 0), new TimeOfDay(4, 0, 0));
    Interval interval = schedule.getTimeframe().getIntervals(now).get(0).getInterval();
    de.avanux.smartapplianceenabler.semp.webservice.Timeframe sempTimeFrame = sempController.createSempTimeFrame(logger, DEVICE_ID, schedule, interval, 0, 0, now);
    Assert.assertEquals(0, (long) sempTimeFrame.getEarliestStart());
    Assert.assertEquals(16200, (long) sempTimeFrame.getLatestEnd());
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) ApplianceLogger(de.avanux.smartapplianceenabler.log.ApplianceLogger) Interval(org.joda.time.Interval) Test(org.junit.Test)

Aggregations

LocalDateTime (org.joda.time.LocalDateTime)120 Test (org.junit.Test)73 Interval (org.joda.time.Interval)27 TimeframeInterval (de.avanux.smartapplianceenabler.schedule.TimeframeInterval)21 DateTime (org.joda.time.DateTime)18 TimeOfDay (de.avanux.smartapplianceenabler.schedule.TimeOfDay)17 Schedule (de.avanux.smartapplianceenabler.schedule.Schedule)12 LocalDate (org.joda.time.LocalDate)12 ArrayList (java.util.ArrayList)8 ConsecutiveDaysTimeframe (de.avanux.smartapplianceenabler.schedule.ConsecutiveDaysTimeframe)6 DayTimeframe (de.avanux.smartapplianceenabler.schedule.DayTimeframe)6 TimeOfDayOfWeek (de.avanux.smartapplianceenabler.schedule.TimeOfDayOfWeek)6 Date (java.util.Date)6 TestBuilder (de.avanux.smartapplianceenabler.test.TestBuilder)4 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)4 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)4 AccAccount (eu.bcvsolutions.idm.acc.entity.AccAccount)4 IdmAuthorizationPolicyDto (eu.bcvsolutions.idm.core.api.dto.IdmAuthorizationPolicyDto)4 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)4 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)4