TimeUtil { public static boolean isAligned(Instant instant, Schedule schedule) { if (!instant.truncatedTo(ChronoUnit.MINUTES).equals(instant)) { return false; } final ExecutionTime executionTime = ExecutionTime.forCron(cron(schedule)); final ZonedDateTime utcDateTime = instant.atZone(UTC); return executionTime.isMatch(utcDateTime); } private  TimeUtil(); static Instant lastInstant(Instant instant, Schedule schedule); static Instant previousInstant(Instant instant, Schedule schedule); static Instant nextInstant(Instant instant, Schedule schedule); static List<Instant> instantsInRange(Instant firstInstant, Instant lastInstant,
                                              Schedule schedule); static List<Instant> instantsInReversedRange(Instant firstInstant, Instant lastInstant,
                                                      Schedule schedule); static boolean isAligned(Instant instant, Schedule schedule); static ZonedDateTime addOffset(ZonedDateTime time, String offset); static ZonedDateTime subtractOffset(ZonedDateTime time, String offset); static Cron cron(Schedule schedule); static Instant offsetInstant(Instant origin, Schedule schedule, int offset);  }
@Test public void shouldTestWellKnownAlignedInstants() { assertTrue(isAligned(parse("2017-02-06T10:00:00.00Z"), Schedule.HOURS)); assertTrue(isAligned(parse("2017-02-06T00:00:00.00Z"), Schedule.DAYS)); assertTrue(isAligned(parse("2017-02-06T00:00:00.00Z"), Schedule.WEEKS)); assertTrue(isAligned(parse("2017-02-01T00:00:00.00Z"), Schedule.MONTHS)); assertTrue(isAligned(parse("2017-01-01T00:00:00.00Z"), Schedule.YEARS)); assertFalse(isAligned(parse("2017-02-06T10:01:00.00Z"), Schedule.HOURS)); assertFalse(isAligned(parse("2017-02-06T01:00:00.00Z"), Schedule.DAYS)); assertFalse(isAligned(parse("2017-02-07T00:00:00.00Z"), Schedule.WEEKS)); assertFalse(isAligned(parse("2017-02-02T00:00:00.00Z"), Schedule.MONTHS)); assertFalse(isAligned(parse("2017-01-02T00:00:00.00Z"), Schedule.YEARS)); }
@Test public void shouldTestCustomAlignedInstants() { Schedule custom = Schedule.parse("15,42 10 * * *"); assertTrue(isAligned(parse("2017-02-06T10:15:00.00Z"), custom)); assertTrue(isAligned(parse("2017-02-06T10:42:00.00Z"), custom)); assertFalse(isAligned(parse("2017-02-06T10:00:00.00Z"), custom)); assertFalse(isAligned(parse("2017-02-06T11:15:00.00Z"), custom)); }