use of org.joda.time.LocalDateTime in project SmartApplianceEnabler by camueller.
the class DayTimeframe method buildMidnightAdjustedInterval.
protected Interval buildMidnightAdjustedInterval(LocalDateTime now) {
if (start != null && end != null) {
LocalDateTime earliestStartDateTime = new LocalDate(now).toLocalDateTime(start.toLocalTime());
LocalDateTime latestEndDateTime = new LocalDate(now).toLocalDateTime(end.toLocalTime());
if (isOverMidnight(earliestStartDateTime, latestEndDateTime)) {
if (now.toLocalTime().isAfter(start.toLocalTime())) {
// before midnight
latestEndDateTime = latestEndDateTime.plusHours(24);
} else if (now.toLocalTime().isBefore(end.toLocalTime())) {
// after midnight, before end
earliestStartDateTime = earliestStartDateTime.minusHours(24);
} else {
// after midnight, after end
latestEndDateTime = latestEndDateTime.plusHours(24);
}
}
return new Interval(earliestStartDateTime.toDateTime(), latestEndDateTime.toDateTime()).withChronology(ISOChronology.getInstance());
}
return null;
}
use of org.joda.time.LocalDateTime in project SmartApplianceEnabler by camueller.
the class SempController method planningRequest.
@RequestMapping(value = BASE_URL + "/PlanningRequest", method = RequestMethod.GET, produces = "application/xml")
public String planningRequest(@RequestParam(value = "DeviceId", required = false) String deviceId) {
LocalDateTime now = new LocalDateTime();
List<PlanningRequest> planningRequests = new ArrayList<PlanningRequest>();
if (deviceId != null) {
logger.debug("{}: Planning request requested", deviceId);
Appliance appliance = ApplianceManager.getInstance().findAppliance(deviceId);
PlanningRequest planningRequest = createPlanningRequest(now, appliance);
addPlanningRequest(planningRequests, planningRequest);
} else {
logger.debug("Planning request requested of all devices");
List<Appliance> appliances = ApplianceManager.getInstance().getAppliances();
for (Appliance appliance : appliances) {
PlanningRequest planningRequest = createPlanningRequest(now, appliance);
addPlanningRequest(planningRequests, planningRequest);
}
}
Device2EM device2EM = new Device2EM();
if (planningRequests.size() > 0) {
device2EM.setPlanningRequest(planningRequests);
}
return marshall(device2EM);
}
use of org.joda.time.LocalDateTime in project SmartApplianceEnabler by camueller.
the class ApplianceTest method createRuntimeRequest_TimeFrameOverMidnight_BeforeMidnight.
@Test
public void createRuntimeRequest_TimeFrameOverMidnight_BeforeMidnight() {
LocalDateTime now = toToday(23, 30, 0);
Schedule schedule = new Schedule(7200, null, new TimeOfDay(20, 0, 0), new TimeOfDay(4, 0, 0));
Interval interval = schedule.getTimeframe().getIntervals(now).get(0).getInterval();
RuntimeRequest runtimeRequest = this.appliance.createRuntimeRequest(interval, schedule.getMinRunningTime(), null, now);
Assert.assertEquals(0, (int) runtimeRequest.getEarliestStart());
Assert.assertEquals(16200, (int) runtimeRequest.getLatestEnd());
Assert.assertEquals(7200, (int) runtimeRequest.getMinRunningTime());
Assert.assertNull(runtimeRequest.getMaxRunningTime());
}
use of org.joda.time.LocalDateTime in project SmartApplianceEnabler by camueller.
the class ApplianceTest method getRuntimeRequest_TimeFrameAlreadyStartedButNotYetActive.
@Test
public void getRuntimeRequest_TimeFrameAlreadyStartedButNotYetActive() {
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));
List<RuntimeRequest> runtimeRequests = this.appliance.getRuntimeRequests(now, Collections.singletonList(schedule), null, 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 org.joda.time.LocalDateTime 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));
}
Aggregations