List of utility methods to do LocalDate Between
int | daysBetween(LocalDate date1, LocalDate date2) days Between Period period = Period.between(date1, date2);
return period.getDays();
|
long | daysBetween(LocalDate firstDate, LocalDate secondDate) Returns the number of days between two dates. int firstYear = firstDate.getYear(); int secondYear = secondDate.getYear(); if (firstYear == secondYear) { return doy(secondDate) - doy(firstDate); if ((firstYear + 1) == secondYear) { return (firstDate.lengthOfYear() - doy(firstDate)) + doy(secondDate); return secondDate.toEpochDay() - firstDate.toEpochDay(); |
List | getLocalDatesBetween(final LocalDate localDate1, final LocalDate localDate2) get Local Dates Between if (localDate1 == null || localDate2 == null) { return Collections.emptyList(); if (localDate1.equals(localDate2)) { return Lists.newArrayList(localDate1); final int daysBetween = (int) Math.abs(ChronoUnit.DAYS.between(localDate1, localDate2)); final List<LocalDate> localDatesBetween = Lists.newArrayListWithExpectedSize(daysBetween + 1); ... |
LocalDate | getRandomLocalDateBetween(int startYear, int endYear) get Random Local Date Between Random random = new Random(); int min = (int) LocalDate.of(startYear, 1, 1).toEpochDay(); int max = (int) LocalDate.of(endYear, 1, 1).toEpochDay(); long randomDay = min + random.nextInt(max - min); return LocalDate.ofEpochDay(randomDay); |
Boolean | isBetween(LocalDate date, LocalDate before, LocalDate after) is Between return date.isAfter(before) && date.isBefore(after);
|
boolean | isBetween13And18YearsBetween(LocalDate birthLocalDate, LocalDate now) is Between And Years Between int years = Period.between(birthLocalDate, now).getYears(); return years >= 13 && years < 18; |
boolean | isBetweenDates(LocalDate date, LocalDate start, LocalDate end) is Between Dates return date.isAfter(start) && date.isBefore(end);
|
boolean | isBetweenIncl(@Nullable final LocalDate aDate, @Nullable final LocalDate aLowerBound, @Nullable final LocalDate aUpperBound) is Between Incl if (aDate == null || aLowerBound == null || aUpperBound == null) return false; return !aLowerBound.isAfter(aDate) && !aDate.isAfter(aUpperBound); |