@Test public void nextDayOfSundayBefore22OClockIsSunday22OClockLondonTime() { final D1 cut = new D1(); assertThat(cut.instantOfNextFrame( LocalDate.of(2013, Month.SEPTEMBER, 22).atTime(20, 4, 52, 5721).toInstant(ZoneOffset.ofHours(1)))) .isEqualTo(LocalDate.of(2013, Month.SEPTEMBER, 22).atTime(22, 0, 0, 0) .toInstant(ZoneOffset.ofHours(1))); assertThat(cut.instantOfNextFrame( LocalDate.of(2004, Month.JANUARY, 11).atTime(20, 4, 52, 5721).toInstant(ZoneOffset.ofHours(0)))) .isEqualTo(LocalDate.of(2004, Month.JANUARY, 11).atTime(22, 0, 0, 0) .toInstant(ZoneOffset.ofHours(0))); assertThat(cut.instantOfNextFrame( LocalDate.of(2014, Month.OCTOBER, 26).atTime(0, 15, 0, 0).toInstant(ZoneOffset.ofHours(1)))).isEqualTo( LocalDate.of(2014, Month.OCTOBER, 26).atTime(22, 0, 0, 0).toInstant(ZoneOffset.ofHours(0))); assertThat(cut.instantOfNextFrame( LocalDate.of(2014, Month.MARCH, 30).atTime(0, 26, 7, 1).toInstant(ZoneOffset.ofHours(0)))).isEqualTo( LocalDate.of(2014, Month.MARCH, 30).atTime(22, 0, 0, 0).toInstant(ZoneOffset.ofHours(1))); assertThat(cut.instantOfNextFrame( LocalDate.of(2013, Month.SEPTEMBER, 22).atTime(22, 5, 52, 5721).toInstant(ZoneOffset.ofHours(1)))) .isEqualTo(LocalDate.of(2013, Month.SEPTEMBER, 24).atTime(0, 0, 0, 0) .toInstant(ZoneOffset.ofHours(1))); }
@Override public Instant instantOfNextFrame(final Instant instant) { final ZonedDateTime britishTime = instant.atZone(BRITISH_TIME_ZONE); final DayOfWeek britishDay = britishTime.getDayOfWeek(); if (britishDay != SUNDAY) { return removeMinutesAndLess(britishTime).withHour(0).plus(1, DAYS).toInstant(); } final ZonedDateTime britishTimeCorrectTimeValues = removeMinutesAndLess(britishTime).withHour(22); if (britishTime.getDayOfWeek() == SUNDAY) { if (britishTime.isBefore(britishTimeCorrectTimeValues)) { return britishTimeCorrectTimeValues.toInstant(); } return removeMinutesAndLess(britishTime).withHour(0).plus(2, DAYS).toInstant(); } return britishTimeCorrectTimeValues.with(TemporalAdjusters.next(SUNDAY)).toInstant(); }
D1 implements TimeFrame { @Override public Instant instantOfNextFrame(final Instant instant) { final ZonedDateTime britishTime = instant.atZone(BRITISH_TIME_ZONE); final DayOfWeek britishDay = britishTime.getDayOfWeek(); if (britishDay != SUNDAY) { return removeMinutesAndLess(britishTime).withHour(0).plus(1, DAYS).toInstant(); } final ZonedDateTime britishTimeCorrectTimeValues = removeMinutesAndLess(britishTime).withHour(22); if (britishTime.getDayOfWeek() == SUNDAY) { if (britishTime.isBefore(britishTimeCorrectTimeValues)) { return britishTimeCorrectTimeValues.toInstant(); } return removeMinutesAndLess(britishTime).withHour(0).plus(2, DAYS).toInstant(); } return britishTimeCorrectTimeValues.with(TemporalAdjusters.next(SUNDAY)).toInstant(); } }
D1 implements TimeFrame { @Override public Instant instantOfNextFrame(final Instant instant) { final ZonedDateTime britishTime = instant.atZone(BRITISH_TIME_ZONE); final DayOfWeek britishDay = britishTime.getDayOfWeek(); if (britishDay != SUNDAY) { return removeMinutesAndLess(britishTime).withHour(0).plus(1, DAYS).toInstant(); } final ZonedDateTime britishTimeCorrectTimeValues = removeMinutesAndLess(britishTime).withHour(22); if (britishTime.getDayOfWeek() == SUNDAY) { if (britishTime.isBefore(britishTimeCorrectTimeValues)) { return britishTimeCorrectTimeValues.toInstant(); } return removeMinutesAndLess(britishTime).withHour(0).plus(2, DAYS).toInstant(); } return britishTimeCorrectTimeValues.with(TemporalAdjusters.next(SUNDAY)).toInstant(); }  }
D1 implements TimeFrame { @Override public Instant instantOfNextFrame(final Instant instant) { final ZonedDateTime britishTime = instant.atZone(BRITISH_TIME_ZONE); final DayOfWeek britishDay = britishTime.getDayOfWeek(); if (britishDay != SUNDAY) { return removeMinutesAndLess(britishTime).withHour(0).plus(1, DAYS).toInstant(); } final ZonedDateTime britishTimeCorrectTimeValues = removeMinutesAndLess(britishTime).withHour(22); if (britishTime.getDayOfWeek() == SUNDAY) { if (britishTime.isBefore(britishTimeCorrectTimeValues)) { return britishTimeCorrectTimeValues.toInstant(); } return removeMinutesAndLess(britishTime).withHour(0).plus(2, DAYS).toInstant(); } return britishTimeCorrectTimeValues.with(TemporalAdjusters.next(SUNDAY)).toInstant(); }  @Override Instant instantOfNextFrame(final Instant instant); @Override boolean areInSameTimeFrame(final Instant instant1, final Instant instant2); }
D1 implements TimeFrame { @Override public Instant instantOfNextFrame(final Instant instant) { final ZonedDateTime britishTime = instant.atZone(BRITISH_TIME_ZONE); final DayOfWeek britishDay = britishTime.getDayOfWeek(); if (britishDay != SUNDAY) { return removeMinutesAndLess(britishTime).withHour(0).plus(1, DAYS).toInstant(); } final ZonedDateTime britishTimeCorrectTimeValues = removeMinutesAndLess(britishTime).withHour(22); if (britishTime.getDayOfWeek() == SUNDAY) { if (britishTime.isBefore(britishTimeCorrectTimeValues)) { return britishTimeCorrectTimeValues.toInstant(); } return removeMinutesAndLess(britishTime).withHour(0).plus(2, DAYS).toInstant(); } return britishTimeCorrectTimeValues.with(TemporalAdjusters.next(SUNDAY)).toInstant(); }  @Override Instant instantOfNextFrame(final Instant instant); @Override boolean areInSameTimeFrame(final Instant instant1, final Instant instant2);  }