DateTimeUtil { static ZonedDateTime truncateToRankingDateTime(ZonedDateTime dateTime) { if (dateTime.getHour() < 3) { dateTime = dateTime.minusDays(1).withHour(15); } else if (dateTime.getHour() < 15) { dateTime = dateTime.withHour(3); } else { dateTime = dateTime.withHour(15); } return dateTime.truncatedTo(ChronoUnit.HOURS); }  static ZonedDateTime now(); static ZonedDateTime rankingDateTime(); static ZonedDateTime dateTimeFromTimestamp(Timestamp timestamp); static ZonedDateTime dateTimeFromEpoch(long epoch); static ZonedDateTime dateTimeFromString(String text); static Calendar getCalender(); static String formatMonth(ZonedDateTime dateTime); static String formatDate(ZonedDateTime dateTime); static String formatDateTime(ZonedDateTime dateTime);  }
@Test @DisplayName("日時を当日の3時に丸める") public void truncateToRankingDateTimeTodayAM() { ZonedDateTime expected = ZonedDateTime.of(2000, 1, 1, 3, 0, 0, 0, JST); ZonedDateTime earlier = ZonedDateTime.of(2000, 1, 1, 3, 0, 0, 0, JST); ZonedDateTime later = ZonedDateTime.of(2000, 1, 1, 14, 59, 59, 999999, JST); assertEquals(expected, DateTimeUtil.truncateToRankingDateTime(earlier)); assertEquals(expected, DateTimeUtil.truncateToRankingDateTime(later)); }
@Test @DisplayName("日時を当日の15時に丸める") public void truncateToRankingDateTimeTodayPM() { ZonedDateTime expected = ZonedDateTime.of(2000, 1, 1, 15, 0, 0, 0, JST); ZonedDateTime earlier = ZonedDateTime.of(2000, 1, 1, 15, 0, 0, 0, JST); ZonedDateTime later = ZonedDateTime.of(2000, 1, 1, 23, 59, 59, 999999, JST); assertEquals(expected, DateTimeUtil.truncateToRankingDateTime(earlier)); assertEquals(expected, DateTimeUtil.truncateToRankingDateTime(later)); }
@Test @DisplayName("日時を前日の15時に丸める") public void truncateToRankingDateTimeYesterdayPM() { ZonedDateTime expected = ZonedDateTime.of(1999, 12, 31, 15, 0, 0, 0, JST); ZonedDateTime earlier = ZonedDateTime.of(2000, 1, 1, 0, 0, 0, 0, JST); ZonedDateTime later = ZonedDateTime.of(2000, 1, 1, 2, 59, 59, 999999, JST); assertEquals(expected, DateTimeUtil.truncateToRankingDateTime(earlier)); assertEquals(expected, DateTimeUtil.truncateToRankingDateTime(later)); }