commit
f9f8a39631
|
@ -4,6 +4,7 @@ import lombok.Data;
|
|||
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -71,14 +72,22 @@ public class DateRange {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Month Key, this key will include current month.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public List<String> getMonthKeys() {
|
||||
List<String> monthKeys = new ArrayList<>();
|
||||
|
||||
LocalDate currentDate = this.start;
|
||||
|
||||
while (currentDate.isBefore(this.end)) {
|
||||
monthKeys.add(currentDate.format(DateTimeFormatter.ofPattern("yyyy-MM")));
|
||||
long monthsBetween = ChronoUnit.MONTHS.between(start, end);
|
||||
|
||||
for (int i = 0; i < monthsBetween; i++) {
|
||||
currentDate = currentDate.plusMonths(1);
|
||||
monthKeys.add(currentDate.format(DateTimeFormatter.ofPattern("yyyy-MM")));
|
||||
|
||||
}
|
||||
|
||||
return monthKeys;
|
||||
|
|
Loading…
Reference in New Issue