Search in sources :

Example 61 with LocalDateTime

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

the class DayTimeframeTest method getIntervals_ValidOnlyOnHoliday_HolidaySet.

@Test
public void getIntervals_ValidOnlyOnHoliday_HolidaySet() {
    DayTimeframe timeframe = new DayTimeframe(new TimeOfDay(10, 0, 0), new TimeOfDay(12, 0, 0), Collections.singletonList(8));
    LocalDateTime now = toDayOfWeek(1, 9, 0, 0);
    timeframe.setHolidays(Collections.singletonList(now.toLocalDate()));
    List<TimeframeInterval> intervals = timeframe.getIntervals(now);
    Assert.assertEquals(1, intervals.size());
    Assert.assertEquals(new Interval(toDayOfWeek(now, 1, 10, 0, 0).toDateTime(), toDayOfWeek(now, 1, 12, 0, 0).toDateTime()), intervals.get(0).getInterval());
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) Interval(org.joda.time.Interval) Test(org.junit.Test)

Example 62 with LocalDateTime

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

the class DayTimeframeTest method getIntervals_ValidOnSundayAndHoliday_HolidayIsSunday.

@Test
public void getIntervals_ValidOnSundayAndHoliday_HolidayIsSunday() {
    DayTimeframe timeframe = new DayTimeframe(new TimeOfDay(10, 0, 0), new TimeOfDay(12, 0, 0), Arrays.asList(7, 8));
    LocalDateTime now = toDayOfWeek(1, 9, 0, 0);
    timeframe.setHolidays(Collections.singletonList(now.toLocalDate().plusDays(6)));
    List<TimeframeInterval> intervals = timeframe.getIntervals(now);
    Assert.assertEquals(1, intervals.size());
    Assert.assertEquals(new Interval(toDayOfWeek(now, 7, 10, 0, 0).toDateTime(), toDayOfWeek(now, 7, 12, 0, 0).toDateTime()), intervals.get(0).getInterval());
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) Interval(org.joda.time.Interval) Test(org.junit.Test)

Example 63 with LocalDateTime

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

the class DayTimeframeTest method getIntervals_ValidOnSundayAndHoliday_HolidayIsThursday.

@Test
public void getIntervals_ValidOnSundayAndHoliday_HolidayIsThursday() {
    DayTimeframe timeframe = new DayTimeframe(new TimeOfDay(10, 0, 0), new TimeOfDay(12, 0, 0), Arrays.asList(7, 8));
    LocalDateTime now = toDayOfWeek(1, 9, 0, 0);
    timeframe.setHolidays(Collections.singletonList(now.toLocalDate().plusDays(3)));
    List<TimeframeInterval> intervals = timeframe.getIntervals(now);
    Assert.assertEquals(2, intervals.size());
    Assert.assertEquals(new Interval(toDayOfWeek(now, 4, 10, 0, 0).toDateTime(), toDayOfWeek(now, 4, 12, 0, 0).toDateTime()), intervals.get(0).getInterval());
    Assert.assertEquals(new Interval(toDayOfWeek(now, 7, 10, 0, 0).toDateTime(), toDayOfWeek(now, 7, 12, 0, 0).toDateTime()), intervals.get(1).getInterval());
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) Interval(org.joda.time.Interval) Test(org.junit.Test)

Example 64 with LocalDateTime

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

the class DayTimeframeTest method getIntervals_DayOfWeekNotMatching_BeforeIntervalStart.

@Test
public void getIntervals_DayOfWeekNotMatching_BeforeIntervalStart() {
    DayTimeframe timeframe = new DayTimeframe(new TimeOfDay(10, 0, 0), new TimeOfDay(12, 0, 0), Collections.singletonList(3));
    LocalDateTime now = toDayOfWeek(1, 9, 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());
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) Interval(org.joda.time.Interval) Test(org.junit.Test)

Example 65 with LocalDateTime

use of org.joda.time.LocalDateTime 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) Interval(org.joda.time.Interval)

Aggregations

LocalDateTime (org.joda.time.LocalDateTime)66 Test (org.junit.Test)35 DateTime (org.joda.time.DateTime)15 Interval (org.joda.time.Interval)12 LocalDate (org.joda.time.LocalDate)11 ArrayList (java.util.ArrayList)5 Date (java.util.Date)5 ApplianceLogger (de.avanux.smartapplianceenabler.log.ApplianceLogger)4 BigDecimal (java.math.BigDecimal)4 BigInteger (java.math.BigInteger)4 DateTimeZone (org.joda.time.DateTimeZone)4 Person (org.qi4j.test.indexing.model.Person)4 HashMap (java.util.HashMap)3 Chronology (org.joda.time.Chronology)3 LocalTime (org.joda.time.LocalTime)3 de.avanux.smartapplianceenabler.appliance (de.avanux.smartapplianceenabler.appliance)2 BuddhistChronology (org.joda.time.chrono.BuddhistChronology)2 GJChronology (org.joda.time.chrono.GJChronology)2 ISOChronology (org.joda.time.chrono.ISOChronology)2 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)2