DateUtils { public static Date getMediumDate( String string ) { return safeParseDateTime( string, MEDIUM_DATE_FORMAT ); }  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 testGetMediumDate() { assertEquals( new DateTime( 2014, 5, 18, 0, 0, 0, 0 ).toDate(), DateUtils.getMediumDate( "2014-05-18" ) ); assertEquals( new DateTime( 2015, 11, 3, 0, 0, 0, 0 ).toDate(), DateUtils.getMediumDate( "2015-11-03" ) ); assertNull( DateUtils.getMediumDate( null ) ); }
@Test( expected = IllegalArgumentException.class ) public void testGetInvalidMediumDate() { DateUtils.getMediumDate( "StringWhichIsNotADate" ); }