!6 更新 3 个月的数据需要包含当前月份

Merge pull request !6 from HoneyMoose/USVT-108
This commit is contained in:
HoneyMoose 2022-11-13 20:17:31 +00:00 committed by Gitee
commit f9f8a39631
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
1 changed files with 11 additions and 2 deletions

View File

@ -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;