diff --git a/common/src/main/java/com/tencent/supersonic/common/util/DateUtils.java b/common/src/main/java/com/tencent/supersonic/common/util/DateUtils.java index 5d62163a8..6e828a69f 100644 --- a/common/src/main/java/com/tencent/supersonic/common/util/DateUtils.java +++ b/common/src/main/java/com/tencent/supersonic/common/util/DateUtils.java @@ -1,6 +1,8 @@ package com.tencent.supersonic.common.util; +import com.google.common.collect.Lists; import com.tencent.supersonic.common.pojo.Constants; +import lombok.extern.slf4j.Slf4j; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.time.LocalDate; @@ -16,7 +18,6 @@ import java.util.Calendar; import java.util.Date; import java.util.List; import java.util.Objects; -import lombok.extern.slf4j.Slf4j; @Slf4j public class DateUtils { @@ -147,25 +148,29 @@ public class DateUtils { } public static List getDateList(String startDateStr, String endDateStr, String period) { - LocalDate startDate = LocalDate.parse(startDateStr); - LocalDate endDate = LocalDate.parse(endDateStr); - - List datesInRange = new ArrayList<>(); - LocalDate currentDate = startDate; - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM"); - while (!currentDate.isAfter(endDate)) { - if (Constants.MONTH.equals(period)) { - datesInRange.add(currentDate.format(formatter)); - currentDate = currentDate.plusMonths(1); - } else if (Constants.WEEK.equals(period)) { - datesInRange.add(currentDate.format(DateTimeFormatter.ISO_DATE)); - currentDate = currentDate.plusWeeks(1); - } else { - datesInRange.add(currentDate.format(DateTimeFormatter.ISO_DATE)); - currentDate = currentDate.plusDays(1); + try { + LocalDate startDate = LocalDate.parse(startDateStr); + LocalDate endDate = LocalDate.parse(endDateStr); + List datesInRange = new ArrayList<>(); + LocalDate currentDate = startDate; + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM"); + while (!currentDate.isAfter(endDate)) { + if (Constants.MONTH.equals(period)) { + datesInRange.add(currentDate.format(formatter)); + currentDate = currentDate.plusMonths(1); + } else if (Constants.WEEK.equals(period)) { + datesInRange.add(currentDate.format(DateTimeFormatter.ISO_DATE)); + currentDate = currentDate.plusWeeks(1); + } else { + datesInRange.add(currentDate.format(DateTimeFormatter.ISO_DATE)); + currentDate = currentDate.plusDays(1); + } } + return datesInRange; + } catch (Exception e) { + log.info("parse date failed, startDate:{}, endDate:{}", startDateStr, endDateStr, e); } - return datesInRange; + return Lists.newArrayList(); } public static boolean isAnyDateString(String value) {