WeeklyTrigger implements Trigger { @Override public ZonedDateTime next(ZonedDateTime previous) { ZonedDateTime next = previous.plusDays(dayOfWeek.getValue() - previous.getDayOfWeek().getValue()).with(time); if (!next.isAfter(previous)) { next = next.plusWeeks(1).with(time); } return next; } WeeklyTrigger(DayOfWeek dayOfWeek, LocalTime time); @Override ZonedDateTime next(ZonedDateTime previous); @Override String toString();  }
@Test void next() { WeeklyTrigger trigger = new WeeklyTrigger(DayOfWeek.WEDNESDAY, of(2, 0)); assertThat(trigger.next(date("2016-01-13T01:00:00"))).isEqualTo(date("2016-01-13T02:00:00")); assertThat(trigger.next(ZonedDateTime.parse("2016-01-13T01:00:00Z"))).isEqualTo("2016-01-13T02:00:00Z"); assertThat(trigger.next(date("2016-01-13T02:00:00"))).isEqualTo(date("2016-01-20T02:00:00")); assertThat(trigger.next(date("2016-01-13T02:30:00"))).isEqualTo(date("2016-01-20T02:00:00")); assertThat(trigger.next(date("2016-01-12T01:00:00"))).isEqualTo(date("2016-01-13T02:00:00")); assertThat(trigger.next(date("2016-01-19T01:00:00"))).isEqualTo(date("2016-01-20T02:00:00")); }