DateUtils { public static Date getNextDate( int hourOfDay, Date now ) { now = now != null ? now : new Date(); DateTime date = new DateTime( now ).plusHours( 1 ); while ( date.getHourOfDay() != hourOfDay ) { date = date.plusHours( 1 ); } return date .withMinuteOfHour( 0 ) .withSecondOfMinute( 0 ) .withMillisOfSecond( 0 ) .toDate(); }  static String getIso8601( Date date ); static String getIso8601NoTz( Date date ); static String getLongGmtDateString( Date date ); static String getLongDateString( Date date ); static String getLongDateString(); static String getMediumDateString( Date date ); static String getMediumDateString(); static String getHttpDateString( Date date ); static Date max( Date date1, Date date2 ); static Date max( Collection<Date> dates ); static Date min( Date date1, Date date2 ); static Date min( Collection<Date> dates ); static Date getMediumDate( String string ); static boolean between( Date baseDate, Date startDate, Date endDate ); static boolean strictlyBetween( Date baseDate, Date startDate, Date endDate ); static long getDays( Date date ); static long getDays( Date startDate, Date endDate ); static long getDaysInclusive( Date startDate, Date endDate ); static int daysBetween( Date startDate, Date endDate ); static boolean isToday( Date date ); static int monthsBetween( Date startDate, Date endDate ); static int daysSince1900( Date date ); static Date getNextDate( int hourOfDay, Date now ); static Date getEpoch(); static String getSqlDateString( Date date ); static boolean dateIsValid( String dateString ); static boolean dateIsValid( org.hisp.dhis.calendar.Calendar calendar, String dateString ); static boolean dateTimeIsValid( final String dateTimeString ); static long getSecondsUntilTomorrow( int hour ); static Date getDateForTomorrow( int hour ); static Date getDateAfterAddition( Date date, int days ); static Date calculateDateFrom( final Date date, final int addend, final int chronoUnit ); static List<Period> setNames( List<Period> periods, I18nFormat format ); static String getPrettyInterval( Date start, Date end ); static String getPrettyInterval( long ms ); static Date parseDate( final String dateString ); static Date getDate( LocalDateTime time ); static Date nowMinusDuration( String duration ); static Duration getDuration( String duration ); static Timestamp asTimestamp( Date date ); static java.sql.Date asSqlDate( Date date ); static Date getLatest( Date... dates ); static Date removeTimeStamp( Date date ); static final PeriodFormatter DAY_SECOND_FORMAT; static final double DAYS_IN_YEAR; }
@Test public void getNextDate() { Date now1 = new DateTime( 2019, 4, 6, 15, 2, 24 ).toDate(); Date now2 = new DateTime( 2019, 4, 7, 3, 2, 35 ).toDate(); assertEquals( new DateTime( 2019, 4, 6, 19, 0, 0, 0 ).toDate(), DateUtils.getNextDate( 19, now1 ) ); assertEquals( new DateTime( 2019, 4, 6, 21, 0, 0, 0 ).toDate(), DateUtils.getNextDate( 21, now1 ) ); assertEquals( new DateTime( 2019, 4, 7, 4, 0, 0, 0 ).toDate(), DateUtils.getNextDate( 4, now1 ) ); assertEquals( new DateTime( 2019, 4, 7, 15, 0, 0, 0 ).toDate(), DateUtils.getNextDate( 15, now1 ) ); assertEquals( new DateTime( 2019, 4, 8, 2, 0, 0, 0 ).toDate(), DateUtils.getNextDate( 2, now2 ) ); assertEquals( new DateTime( 2019, 4, 7, 5, 0, 0, 0 ).toDate(), DateUtils.getNextDate( 5, now2 ) ); assertEquals( new DateTime( 2019, 4, 7, 17, 0, 0, 0 ).toDate(), DateUtils.getNextDate( 17, now2 ) ); assertNotNull( DateUtils.getNextDate( 4, null ) ); }