@Test public void sundayEndsBefore22oClockLondonTime() { final D1 cut = new D1(); assertThat(cut.areInSameTimeFrame( LocalDate.of(2014, Month.JUNE, 22).atTime(0, 0, 0, 0).toInstant(ZoneOffset.ofHours(1)), LocalDate.of(2014, Month.JUNE, 22).atTime(21, 59, 59, 99999).toInstant(ZoneOffset.ofHours(1)))) .isTrue(); assertThat(cut.areInSameTimeFrame( LocalDate.of(2014, Month.JUNE, 8).atTime(12, 45, 23, 321).toInstant(ZoneOffset.ofHours(1)), LocalDate.of(2014, Month.JUNE, 8).atTime(7, 32, 12, 543).toInstant(ZoneOffset.ofHours(1)))).isTrue(); assertThat(cut.areInSameTimeFrame( LocalDate.of(2005, Month.DECEMBER, 18).atTime(0, 0, 0, 0).toInstant(ZoneOffset.ofHours(0)), LocalDate.of(2005, Month.DECEMBER, 18).atTime(21, 59, 59, 99999).toInstant(ZoneOffset.ofHours(0)))) .isTrue(); assertThat(cut.areInSameTimeFrame( LocalDate.of(2014, Month.JUNE, 22).atTime(0, 0, 0, 0).toInstant(ZoneOffset.ofHours(1)), LocalDate.of(2014, Month.JUNE, 22).atTime(22, 0, 0, 0).toInstant(ZoneOffset.ofHours(1)))).isFalse(); assertThat(cut.areInSameTimeFrame( LocalDate.of(2014, Month.MAY, 11).atTime(15, 47, 34, 785).toInstant(ZoneOffset.ofHours(1)), LocalDate.of(2014, Month.MAY, 11).atTime(23, 4, 32, 78).toInstant(ZoneOffset.ofHours(1)))).isFalse(); assertThat(cut.areInSameTimeFrame( LocalDate.of(2014, Month.JUNE, 22).atTime(0, 0, 0, 0).toInstant(ZoneOffset.ofHours(1)), LocalDate.of(2014, Month.JUNE, 23).atTime(0, 0, 0, 0).toInstant(ZoneOffset.ofHours(1)))).isFalse(); assertThat(cut.areInSameTimeFrame( LocalDate.of(2014, Month.JUNE, 22).atTime(0, 0, 0, 0).toInstant(ZoneOffset.ofHours(1)), LocalDate.of(2015, Month.JUNE, 22).atTime(0, 0, 0, 0).toInstant(ZoneOffset.ofHours(1)))).isFalse(); }
@Override public boolean areInSameTimeFrame(final Instant instant1, final Instant instant2) { final ZonedDateTime britishTime = instant1.atZone(BRITISH_TIME_ZONE); final DayOfWeek britishDay = britishTime.getDayOfWeek(); final ZonedDateTime localBase = britishTime.withHour(0).withMinute(0).withSecond(0).withNano(0); final ZonedDateTime start; final ZonedDateTime end; if (britishDay == SUNDAY) { if (britishTime.isBefore(localBase.withHour(22))) { start = localBase; end = localBase.withHour(22); } else { start = localBase.withHour(22); end = localBase.plusDays(2); } } else if (britishDay == MONDAY) { start = localBase.minusDays(1).withHour(22); end = localBase.plusDays(1); } else { start = localBase; end = localBase.plusDays(1); } return instant2.equals(start.toInstant()) || (instant2.isAfter(start.toInstant()) && instant2.isBefore(end.toInstant())); }
D1 implements TimeFrame { @Override public boolean areInSameTimeFrame(final Instant instant1, final Instant instant2) { final ZonedDateTime britishTime = instant1.atZone(BRITISH_TIME_ZONE); final DayOfWeek britishDay = britishTime.getDayOfWeek(); final ZonedDateTime localBase = britishTime.withHour(0).withMinute(0).withSecond(0).withNano(0); final ZonedDateTime start; final ZonedDateTime end; if (britishDay == SUNDAY) { if (britishTime.isBefore(localBase.withHour(22))) { start = localBase; end = localBase.withHour(22); } else { start = localBase.withHour(22); end = localBase.plusDays(2); } } else if (britishDay == MONDAY) { start = localBase.minusDays(1).withHour(22); end = localBase.plusDays(1); } else { start = localBase; end = localBase.plusDays(1); } return instant2.equals(start.toInstant()) || (instant2.isAfter(start.toInstant()) && instant2.isBefore(end.toInstant())); } }
D1 implements TimeFrame { @Override public boolean areInSameTimeFrame(final Instant instant1, final Instant instant2) { final ZonedDateTime britishTime = instant1.atZone(BRITISH_TIME_ZONE); final DayOfWeek britishDay = britishTime.getDayOfWeek(); final ZonedDateTime localBase = britishTime.withHour(0).withMinute(0).withSecond(0).withNano(0); final ZonedDateTime start; final ZonedDateTime end; if (britishDay == SUNDAY) { if (britishTime.isBefore(localBase.withHour(22))) { start = localBase; end = localBase.withHour(22); } else { start = localBase.withHour(22); end = localBase.plusDays(2); } } else if (britishDay == MONDAY) { start = localBase.minusDays(1).withHour(22); end = localBase.plusDays(1); } else { start = localBase; end = localBase.plusDays(1); } return instant2.equals(start.toInstant()) || (instant2.isAfter(start.toInstant()) && instant2.isBefore(end.toInstant())); }  }
D1 implements TimeFrame { @Override public boolean areInSameTimeFrame(final Instant instant1, final Instant instant2) { final ZonedDateTime britishTime = instant1.atZone(BRITISH_TIME_ZONE); final DayOfWeek britishDay = britishTime.getDayOfWeek(); final ZonedDateTime localBase = britishTime.withHour(0).withMinute(0).withSecond(0).withNano(0); final ZonedDateTime start; final ZonedDateTime end; if (britishDay == SUNDAY) { if (britishTime.isBefore(localBase.withHour(22))) { start = localBase; end = localBase.withHour(22); } else { start = localBase.withHour(22); end = localBase.plusDays(2); } } else if (britishDay == MONDAY) { start = localBase.minusDays(1).withHour(22); end = localBase.plusDays(1); } else { start = localBase; end = localBase.plusDays(1); } return instant2.equals(start.toInstant()) || (instant2.isAfter(start.toInstant()) && instant2.isBefore(end.toInstant())); }  @Override Instant instantOfNextFrame(final Instant instant); @Override boolean areInSameTimeFrame(final Instant instant1, final Instant instant2); }
D1 implements TimeFrame { @Override public boolean areInSameTimeFrame(final Instant instant1, final Instant instant2) { final ZonedDateTime britishTime = instant1.atZone(BRITISH_TIME_ZONE); final DayOfWeek britishDay = britishTime.getDayOfWeek(); final ZonedDateTime localBase = britishTime.withHour(0).withMinute(0).withSecond(0).withNano(0); final ZonedDateTime start; final ZonedDateTime end; if (britishDay == SUNDAY) { if (britishTime.isBefore(localBase.withHour(22))) { start = localBase; end = localBase.withHour(22); } else { start = localBase.withHour(22); end = localBase.plusDays(2); } } else if (britishDay == MONDAY) { start = localBase.minusDays(1).withHour(22); end = localBase.plusDays(1); } else { start = localBase; end = localBase.plusDays(1); } return instant2.equals(start.toInstant()) || (instant2.isAfter(start.toInstant()) && instant2.isBefore(end.toInstant())); }  @Override Instant instantOfNextFrame(final Instant instant); @Override boolean areInSameTimeFrame(final Instant instant1, final Instant instant2);  }