public static List<String> collectLocalDates(String timeStart, String timeEnd, String type) {
if ("2".equals(type)) {
return collectLocalDates(LocalDate.parse(timeStart), LocalDate.parse(timeEnd), type);
} else {
return collectLocalDates(LocalDate.parse(timeStart), LocalDate.parse(timeEnd), type);
}
}
public static List<String> collectLocalDates(LocalDate start, LocalDate end, String type) {
if ("2".equals(type)) {
return Stream.iterate(start, localDate -> localDate.plusDays(1))
.limit(ChronoUnit.DAYS.between(start, end) + 1)
.map(DateTimeUtil::getMonthAndDay)
.collect(Collectors.toList());
} else {
return Stream.iterate(start, localDate -> localDate.plusDays(1))
.limit(ChronoUnit.DAYS.between(start, end) + 1)
.map(LocalDate::toString)
.collect(Collectors.toList());
}
}
public static String getMonthAndDay(LocalDate localDate) {
int monthValue = localDate.getMonthValue();
String month = monthValue < 10 ? "0" + monthValue : monthValue + "";
int dayOfMonth = localDate.getDayOfMonth();
String day = dayOfMonth < 10 ? "0" + dayOfMonth : dayOfMonth + "";
return month + "-" + day;
}