DateUtil { public static boolean isBetweenHours(int hour, int startHour, int endHour) { if (startHour == endHour) { return true; } else { boolean afterStartHour = crossesMidnight(startHour, endHour) ? ((hour >= startHour) || (hour >= MIDNIGHT_HOUR)) : (hour >= startHour); boolean beforeEndHour = hour < endHour || endHour == MIDNIGHT_HOUR; return afterStartHour && beforeEndHour; } }  static Instant truncatedToDay(Instant date); static Instant truncatedToWeek(Instant date); static Instant snapToSeconds(Instant date, int seconds); static Instant truncatedToSeconds(Instant date); static String epochSecondToString(long metricTimestamp); static Instant epochSecondToInstant(long metricTimestamp); static boolean isBetweenHours(int hour, int startHour, int endHour); static boolean crossesMidnight(int startHour, int endHour); static ZonedDateTime instantToUTCDateTime(Instant epochSecond); static final int MIDNIGHT_HOUR; }
@Test public void testIsBetweenHours_AllDay() { assertTrue(DateUtil.isBetweenHours(00, 00, 00)); assertTrue(DateUtil.isBetweenHours(01, 01, 01)); }
@Test public void testIsBetweenHours_AfterMidnight() { assertTrue(DateUtil.isBetweenHours(01, 00, 02)); }
@Test public void testIsBetweenHours_SameAsStartHour() { assertTrue(DateUtil.isBetweenHours(01, 01, 02)); assertTrue(DateUtil.isBetweenHours(23, 22, 00)); assertTrue(DateUtil.isBetweenHours(00, 23, 01)); assertTrue(DateUtil.isBetweenHours(00, 00, 23)); }
@Test public void testIsBetweenHours_FalseWhenSameAsEndHour() { assertFalse(DateUtil.isBetweenHours(23, 00, 23)); assertFalse(DateUtil.isBetweenHours(00, 23, 00)); }
@Test public void testIsBetweenHours_FalseWhenOutsideHours() { assertFalse(DateUtil.isBetweenHours(00, 01, 02)); }