DateUtil { public static int getRemainingDays(String startDateString, int noDays) { Date endDate = getEndDate(startDateString, noDays); Calendar cal = Calendar.getInstance(); cal.setTime(endDate); long remainingMills = cal.getTimeInMillis() - Calendar.getInstance().getTimeInMillis(); long days = remainingMills / (24 * 60 * 60 * 1000); return Math.round(days); }  static boolean isMoreThanOneDayBefore(Date date); static Date getYesterday(); static Date getDayBefore(Date date); static Date getDayBefore(Date date, int numberOfDays); static String extractDate(Date date, Locale locale); static String extractTime(Date date, Locale locale); static DateFilter getDateFilterFromDDaysBeforeToToday(int days); static String getEndDate(String startDateString, int noDays, Locale locale); static int getRemainingDays(String startDateString, int noDays);  }
@Test public void getRemainingDays_future() { String someDate = "20.03.24"; int days = DateUtil.getRemainingDays(someDate, 3); System.out.println("getRemainingDays: " + days); assertTrue(days > 0); int oneDay = DateUtil.getRemainingDays(someDate, 3) - DateUtil.getRemainingDays(someDate, 2); assertTrue(oneDay == 1); }
@Test public void getRemainingDays_past() { String someDate = "20.03.04"; int days = DateUtil.getRemainingDays(someDate, 3); System.out.println("getRemainingDays: " + days); assertTrue(days < 0); }
@Test public void getRemainingDays_invalidDate() { String someDate = "noDate"; int days = DateUtil.getRemainingDays(someDate, 3); System.out.println("getRemainingDays: " + days); assertTrue(days == 0); }
@Test public void getRemainingDays_emptyArgs() { String someDate = ""; int days = DateUtil.getRemainingDays(someDate, 0); System.out.println("getRemainingDays: " + days); assertTrue(days == 0); }