@Test public void isDayBefore_shouldReturnFalseForFebruary28WhenLeapYear() { Calendar currentDate = Calendar.getInstance(); currentDate.set(2012, Calendar.MARCH, 01); Calendar pastDate = Calendar.getInstance(); pastDate.set(2012, Calendar.FEBRUARY, 28); assertThat(new DateExt(pastDate.getTime()).isDayBefore(currentDate.getTime()), is(false)); }
public boolean isDayBefore(Date anotherDate) { Calendar day = Calendar.getInstance(); day.setTime(date); day.set(Calendar.HOUR_OF_DAY, 0); day.set(Calendar.MINUTE, 0); day.set(Calendar.SECOND, 0); day.set(Calendar.MILLISECOND, 0); Calendar anotherDay = Calendar.getInstance(); anotherDay.setTime(anotherDate); anotherDay.add(Calendar.DAY_OF_YEAR, -1); anotherDay.set(Calendar.HOUR_OF_DAY, 0); anotherDay.set(Calendar.MINUTE, 0); anotherDay.set(Calendar.SECOND, 0); anotherDay.set(Calendar.MILLISECOND, 0); return day.equals(anotherDay); }
DateExt { public boolean isDayBefore(Date anotherDate) { Calendar day = Calendar.getInstance(); day.setTime(date); day.set(Calendar.HOUR_OF_DAY, 0); day.set(Calendar.MINUTE, 0); day.set(Calendar.SECOND, 0); day.set(Calendar.MILLISECOND, 0); Calendar anotherDay = Calendar.getInstance(); anotherDay.setTime(anotherDate); anotherDay.add(Calendar.DAY_OF_YEAR, -1); anotherDay.set(Calendar.HOUR_OF_DAY, 0); anotherDay.set(Calendar.MINUTE, 0); anotherDay.set(Calendar.SECOND, 0); anotherDay.set(Calendar.MILLISECOND, 0); return day.equals(anotherDay); } }
DateExt { public boolean isDayBefore(Date anotherDate) { Calendar day = Calendar.getInstance(); day.setTime(date); day.set(Calendar.HOUR_OF_DAY, 0); day.set(Calendar.MINUTE, 0); day.set(Calendar.SECOND, 0); day.set(Calendar.MILLISECOND, 0); Calendar anotherDay = Calendar.getInstance(); anotherDay.setTime(anotherDate); anotherDay.add(Calendar.DAY_OF_YEAR, -1); anotherDay.set(Calendar.HOUR_OF_DAY, 0); anotherDay.set(Calendar.MINUTE, 0); anotherDay.set(Calendar.SECOND, 0); anotherDay.set(Calendar.MILLISECOND, 0); return day.equals(anotherDay); } DateExt(Date date); }
DateExt { public boolean isDayBefore(Date anotherDate) { Calendar day = Calendar.getInstance(); day.setTime(date); day.set(Calendar.HOUR_OF_DAY, 0); day.set(Calendar.MINUTE, 0); day.set(Calendar.SECOND, 0); day.set(Calendar.MILLISECOND, 0); Calendar anotherDay = Calendar.getInstance(); anotherDay.setTime(anotherDate); anotherDay.add(Calendar.DAY_OF_YEAR, -1); anotherDay.set(Calendar.HOUR_OF_DAY, 0); anotherDay.set(Calendar.MINUTE, 0); anotherDay.set(Calendar.SECOND, 0); anotherDay.set(Calendar.MILLISECOND, 0); return day.equals(anotherDay); } DateExt(Date date); boolean isSameDay(Date anotherDate); boolean isDayBefore(Date anotherDate); Date getDateWithoutTime(); }
DateExt { public boolean isDayBefore(Date anotherDate) { Calendar day = Calendar.getInstance(); day.setTime(date); day.set(Calendar.HOUR_OF_DAY, 0); day.set(Calendar.MINUTE, 0); day.set(Calendar.SECOND, 0); day.set(Calendar.MILLISECOND, 0); Calendar anotherDay = Calendar.getInstance(); anotherDay.setTime(anotherDate); anotherDay.add(Calendar.DAY_OF_YEAR, -1); anotherDay.set(Calendar.HOUR_OF_DAY, 0); anotherDay.set(Calendar.MINUTE, 0); anotherDay.set(Calendar.SECOND, 0); anotherDay.set(Calendar.MILLISECOND, 0); return day.equals(anotherDay); } DateExt(Date date); boolean isSameDay(Date anotherDate); boolean isDayBefore(Date anotherDate); Date getDateWithoutTime();  }