DateHelper { public static List<Integer> getDaysInMonth(Integer month, Integer year) { if (month == null) { return new ArrayList<>(); } Calendar calendar = new GregorianCalendar(); if (year == null) { calendar.set(Calendar.YEAR, 2020); } else { calendar.set(Calendar.YEAR, year); } calendar.set(Calendar.MONTH, month - 1); calendar.set(Calendar.DAY_OF_MONTH, 1); Integer daysInMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH); List<Integer> x = new ArrayList<Integer>(); for (int i = 1; i <= daysInMonth; i++) { x.add(i); } return x; } private  DateHelper(); static SimpleDateFormat getLocalDateFormat(Language language); static String getLocalDatePattern(Language language); static SimpleDateFormat getLocalDateTimeFormat(Language language); static String formatLocalDate(Date date, SimpleDateFormat dateFormat); static String formatShortDate(Date date); static String formatLocalDate(Date date, Language language); static String formatLocalDateTime(Date date, Language language); static String formatTime(Date date); static Date parseTime(String date); static Date parseDate(String date, SimpleDateFormat dateFormat); static Date parseDateWithException(String date); static String formatDateForExport(Date date); static String formatDateWithoutYear(Date date, Language language); static String formatDateWithMonthAbbreviation(Date date); static boolean isSameDay(Date firstDate, Date secondDate); static Date getDateZero(int year, int month, int day); static Date getTime(int hour, int minute); static List<Integer> getDaysInMonth(Integer month, Integer year); static List<Integer> getMonthsInYear(); static List<Integer> getYearsToNow(int startingYear); static List<Integer> getYearsToNow(); static int getFullDaysBetween(Date start, Date end); static int getDaysBetween(Date start, Date end); static List<Date> listDaysBetween(Date start, Date end); static int getWeeksBetween(Date start, Date end); static List<Date> listWeeksBetween(Date start, Date end); static int getMonthsBetween(Date start, Date end); static List<Date> listMonthsBetween(Date start, Date end); static int getYearsBetween(Date start, Date end); static List<Date> listYearsBetween(Date start, Date end); static Date addDays(Date date, int amountOfDays); static Date subtractDays(Date date, int amountOfDays); static Date addWeeks(Date date, int amountOfWeeks); static Date subtractWeeks(Date date, int amountOfWeeks); static Date addMonths(Date date, int amountOfMonths); static Date subtractMonths(Date date, int amountOfMonths); static Date addYears(Date date, int amountOfYears); static Date subtractYears(Date date, int amountOfYears); static Date addSeconds(Date date, int amountOfSeconds); static Date getStartOfDay(Date date); static Date getEndOfDay(Date date); static Date getStartOfWeek(Date date); static Date getEndOfWeek(Date date); static Date getStartOfMonth(Date date); static Date getEndOfMonth(Date date); static Date getStartOfYear(Date date); static Date getEndOfYear(Date date); static boolean isBetween(Date date, Date start, Date end); static Calendar getEpiCalendar(); static EpiWeek getEpiWeek(Date date); static EpiWeek getEpiWeekYearBefore(EpiWeek epiWeek); static EpiWeek getPreviousEpiWeek(Date date); static EpiWeek getPreviousEpiWeek(EpiWeek epiWeek); static EpiWeek getNextEpiWeek(Date date); static EpiWeek getNextEpiWeek(EpiWeek epiWeek); static Date getEpiWeekStart(EpiWeek epiWeek); static Date getEpiWeekEnd(EpiWeek epiWeek); static boolean isEpiWeekAfter(EpiWeek epiWeek, EpiWeek anotherEpiWeek); static int getMaximumEpiWeekNumber(); static List<EpiWeek> createEpiWeekList(int year); static List<EpiWeek> createEpiWeekList(int year, int week); static Date[] calculateEpiWeekReportStartAndEnd(
		Date now,
		EpiWeek epiWeek,
		Date weeklyReportDate,
		Date prevWeeklyReportDate,
		Date nextWeeklyReportDate); static Date[] findDateBounds(String value); static Integer[] findDatePrefix(String value); static Date toCorrectCentury(Date value); static Date toCorrectCentury(Date value, Date reference); static Timestamp toTimestampUpper(Date date); static long now(); static long startTime(); static long durationMillies(long startTimeMilliseconds); static long durationSeconds(long startTimeMilliseconds); static long toSeconds(long milliseconds);  }
@Test public void testGetDaysInMonth() { assertDays(DateHelper.getDaysInMonth(1, 2010), 31); assertDays(DateHelper.getDaysInMonth(2, 2010), 28); assertDays(DateHelper.getDaysInMonth(3, 2010), 31); assertDays(DateHelper.getDaysInMonth(4, 2010), 30); assertDays(DateHelper.getDaysInMonth(5, 2010), 31); assertDays(DateHelper.getDaysInMonth(6, 2010), 30); assertDays(DateHelper.getDaysInMonth(7, 2010), 31); assertDays(DateHelper.getDaysInMonth(8, 2010), 31); assertDays(DateHelper.getDaysInMonth(9, 2010), 30); assertDays(DateHelper.getDaysInMonth(10, 2010), 31); assertDays(DateHelper.getDaysInMonth(11, 2010), 30); assertDays(DateHelper.getDaysInMonth(12, 2010), 31); }
@Test public void testGetDaysInMonthLeapYear() { assertDays(DateHelper.getDaysInMonth(2, 1900), 28); assertDays(DateHelper.getDaysInMonth(2, 2009), 28); assertDays(DateHelper.getDaysInMonth(2, 2010), 28); assertDays(DateHelper.getDaysInMonth(2, 2011), 28); assertDays(DateHelper.getDaysInMonth(2, null), 29); assertDays(DateHelper.getDaysInMonth(2, 2000), 29); assertDays(DateHelper.getDaysInMonth(2, 2008), 29); }