mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-11 20:25:12 +00:00
(improvement)(Headless) Add try catch to avoid date '2024年'/'6月' parse failed causing the entire process to fail (#1040)
Co-authored-by: jolunoluo
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
package com.tencent.supersonic.common.util;
|
package com.tencent.supersonic.common.util;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
import com.tencent.supersonic.common.pojo.Constants;
|
import com.tencent.supersonic.common.pojo.Constants;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
@@ -16,7 +18,6 @@ import java.util.Calendar;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class DateUtils {
|
public class DateUtils {
|
||||||
@@ -147,25 +148,29 @@ public class DateUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static List<String> getDateList(String startDateStr, String endDateStr, String period) {
|
public static List<String> getDateList(String startDateStr, String endDateStr, String period) {
|
||||||
LocalDate startDate = LocalDate.parse(startDateStr);
|
try {
|
||||||
LocalDate endDate = LocalDate.parse(endDateStr);
|
LocalDate startDate = LocalDate.parse(startDateStr);
|
||||||
|
LocalDate endDate = LocalDate.parse(endDateStr);
|
||||||
List<String> datesInRange = new ArrayList<>();
|
List<String> datesInRange = new ArrayList<>();
|
||||||
LocalDate currentDate = startDate;
|
LocalDate currentDate = startDate;
|
||||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");
|
||||||
while (!currentDate.isAfter(endDate)) {
|
while (!currentDate.isAfter(endDate)) {
|
||||||
if (Constants.MONTH.equals(period)) {
|
if (Constants.MONTH.equals(period)) {
|
||||||
datesInRange.add(currentDate.format(formatter));
|
datesInRange.add(currentDate.format(formatter));
|
||||||
currentDate = currentDate.plusMonths(1);
|
currentDate = currentDate.plusMonths(1);
|
||||||
} else if (Constants.WEEK.equals(period)) {
|
} else if (Constants.WEEK.equals(period)) {
|
||||||
datesInRange.add(currentDate.format(DateTimeFormatter.ISO_DATE));
|
datesInRange.add(currentDate.format(DateTimeFormatter.ISO_DATE));
|
||||||
currentDate = currentDate.plusWeeks(1);
|
currentDate = currentDate.plusWeeks(1);
|
||||||
} else {
|
} else {
|
||||||
datesInRange.add(currentDate.format(DateTimeFormatter.ISO_DATE));
|
datesInRange.add(currentDate.format(DateTimeFormatter.ISO_DATE));
|
||||||
currentDate = currentDate.plusDays(1);
|
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) {
|
public static boolean isAnyDateString(String value) {
|
||||||
|
|||||||
Reference in New Issue
Block a user