ExtDateTimeUtils { public static Date daysBefore(Date dateInst, int numDays) { if ((numDays <= 0) || (dateInst == null)) { throw new IllegalArgumentException(); } final Calendar cal = new GregorianCalendar(); cal.setTime(dateInst); cal.add(Calendar.DAY_OF_YEAR, -numDays); 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 testDaysBeforeNegativeValue(){ assertEquals("1 days before ","",ExtDateTimeUtils.daysBefore(new Date(),-1)); }
@Test(expected = IllegalArgumentException.class) public void testDaysBeforeWithNullDate(){ assertEquals("null date ","",ExtDateTimeUtils.daysBefore(null,1)); }
@Test public void testDaysBeforeWithRealDate(){ Date date = new Date(); date.getTime(); Date dateMinusOneDay = new Date(); long millisecondsInOneDay = 86400000L; dateMinusOneDay.setTime(date.getTime() - millisecondsInOneDay); assertEquals("1 days before input date ",dateMinusOneDay,ExtDateTimeUtils.daysBefore(date,1)); }