ExtDateTimeUtils { public static Date endOfDay(Date dateInst) { if (dateInst == null) { throw new IllegalArgumentException(); } final Calendar cal = new GregorianCalendar(); cal.setTime(dateInst); cal.set(Calendar.HOUR_OF_DAY, LAST_HOUR_OF_DAY); cal.set(Calendar.MINUTE, LAST_MINUTE); cal.set(Calendar.SECOND, LAST_SECOND); cal.set(Calendar.MILLISECOND, LAST_MILLISECOND); return cal.getTime(); } private  ExtDateTimeUtils(); static String timestampToHumanDateAndTime(long timestamp); static String dateToHumanDateAndTime(Date date); static String dateToHuman(Date date); static Timestamp getCurrentTimeStamp(); static Date daysBefore(Date dateInst, int numDays); static Date daysBeforeNow(int numDays); static Date daysAfter(Date dateInst, int numDays); static Date daysAfterWithoutTimeZone(Date dateInst, int numDays); static Date daysAfterNow(int numDays); static Date startOfDay(Date dateInst); static Date endOfDay(Date dateInst); static Date startOfDayUsingOutputTimeZone(Date dateInst); static Date endOfDayUsingOutputTimeZone(Date dateInst); static final long MILLIS_IN_SECOND; static final long MILLIS_IN_MINUTE; static final long MILLIS_IN_HOUR; static final long MILLIS_IN_DAY; static final int LAST_HOUR_OF_DAY; static final int LAST_MINUTE; static final int LAST_SECOND; static final int LAST_MILLISECOND; }
@Test(expected = IllegalArgumentException.class) public void testEndOfDayWithNullDate(){ assertEquals("Null end of day ","",ExtDateTimeUtils.endOfDay(null)); }
@Test public void testEndOfDay() throws ParseException { Date date; SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss.SSS"); String dateInString = "10-Dec-2015 23:59:59.999"; date = formatter.parse(dateInString); Calendar cal = new GregorianCalendar(); cal.setTime(date); assertEquals("Using endOfDay with a real date ",cal.getTime(),ExtDateTimeUtils.endOfDay(date)); }