use of org.joda.time.LocalDateTime in project joda-time by JodaOrg.
the class TestDateTimeFormatter method testParseLocalDateTime_monthDay_withDefaultYear_feb29.
public void testParseLocalDateTime_monthDay_withDefaultYear_feb29() {
Chronology chrono = GJChronology.getInstanceUTC();
DateTimeFormatter f = DateTimeFormat.forPattern("M d H m").withChronology(chrono).withLocale(Locale.UK).withDefaultYear(2012);
assertEquals(new LocalDateTime(2012, 2, 29, 13, 40, 0, 0, chrono), f.parseLocalDateTime("2 29 13 40"));
}
use of org.joda.time.LocalDateTime in project SmartApplianceEnabler by camueller.
the class SempControllerTest method getPlanningRequest_startingCurrentDetected.
@Test
public void getPlanningRequest_startingCurrentDetected() {
Identification identification = new Identification();
identification.setDeviceId(DEVICE_ID);
DeviceInfo deviceInfo = new DeviceInfo();
deviceInfo.setIdentification(identification);
device2EM.setDeviceInfo(Collections.singletonList(deviceInfo));
Appliance appliance = new Appliance();
appliance.setId(DEVICE_ID);
LocalDateTime now = toToday(9, 0, 0);
Schedule schedule = new Schedule(3600, 3600, new TimeOfDay(11, 0, 0), new TimeOfDay(13, 0, 0));
de.avanux.smartapplianceenabler.appliance.Timeframe timeframe = schedule.getTimeframe();
timeframe.setSchedule(schedule);
RunningTimeMonitor runningTimeMonitor = mock(RunningTimeMonitor.class);
when(runningTimeMonitor.getActiveTimeframeInterval()).thenReturn(timeframe.getIntervals(now).get(0));
when(runningTimeMonitor.getRemainingMinRunningTimeOfCurrentTimeFrame()).thenReturn(schedule.getMinRunningTime());
when(runningTimeMonitor.getRemainingMaxRunningTimeOfCurrentTimeFrame()).thenReturn(schedule.getMaxRunningTime());
appliance.setRunningTimeMonitor(runningTimeMonitor);
Appliances appliances = new Appliances();
appliances.setAppliances(Collections.singletonList(appliance));
ApplianceManager.getInstance().setAppliances(appliances);
appliance.startingCurrentDetected();
// check timeframes for the first time after activation
Device2EM device2EM = sempController.createDevice2EM(now);
List<PlanningRequest> planningRequests = device2EM.getPlanningRequest();
Assert.assertEquals(1, planningRequests.size());
List<Timeframe> timeframes = planningRequests.get(0).getTimeframes();
Assert.assertEquals(1, timeframes.size());
// check again in order to make sure that the timeframe remains active
device2EM = sempController.createDevice2EM(now);
planningRequests = device2EM.getPlanningRequest();
Assert.assertEquals(1, planningRequests.size());
timeframes = planningRequests.get(0).getTimeframes();
Assert.assertEquals(1, timeframes.size());
appliance.finishedCurrentDetected();
when(runningTimeMonitor.getActiveTimeframeInterval()).thenReturn(null);
// check timeframes for the first time after deactivation
device2EM = sempController.createDevice2EM(now);
planningRequests = device2EM.getPlanningRequest();
Assert.assertEquals(0, planningRequests.size());
// check again in order to make sure that the timeframe remains inactive
device2EM = sempController.createDevice2EM(now);
planningRequests = device2EM.getPlanningRequest();
Assert.assertEquals(0, planningRequests.size());
}
use of org.joda.time.LocalDateTime in project SmartApplianceEnabler by camueller.
the class SempControllerTest method createSempTimeFrame_TimeFrameOverMidnight_AfterMidnight.
@Test
public void createSempTimeFrame_TimeFrameOverMidnight_AfterMidnight() {
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(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(12600, (long) sempTimeFrame.getLatestEnd());
}
use of org.joda.time.LocalDateTime 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 org.joda.time.LocalDateTime 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());
}
Aggregations