(improvement) (semantic) support metric data batch download (#358)

Co-authored-by: jolunoluo
This commit is contained in:
LXW
2023-11-10 16:35:17 +08:00
committed by GitHub
parent e537b738e4
commit 8ed7e91221
14 changed files with 589 additions and 67 deletions

View File

@@ -6,9 +6,12 @@ import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import com.tencent.supersonic.common.pojo.Constants;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@@ -126,4 +129,24 @@ public class DateUtils {
return !timeString.equals("00:00:00");
}
public static List<String> getDateList(String startDateStr, String endDateStr, String period) {
LocalDate startDate = LocalDate.parse(startDateStr);
LocalDate endDate = LocalDate.parse(endDateStr);
List<String> datesInRange = new ArrayList<>();
LocalDate currentDate = startDate;
while (!currentDate.isAfter(endDate)) {
datesInRange.add(currentDate.format(DateTimeFormatter.ISO_DATE));
if (Constants.MONTH.equals(period)) {
currentDate = currentDate.plusMonths(1);
} else if (Constants.WEEK.equals(period)) {
currentDate = currentDate.plusWeeks(1);
} else {
currentDate = currentDate.plusDays(1);
}
}
return datesInRange;
}
}

View File

@@ -1,7 +1,11 @@
package com.tencent.supersonic.common.util;
import com.tencent.supersonic.common.pojo.Constants;
import org.assertj.core.util.Lists;
import org.junit.Assert;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.List;
class DateUtilsTest {
@@ -47,4 +51,34 @@ class DateUtilsTest {
dateStr = DateUtils.getBeforeDate(1, DatePeriodEnum.MONTH);
//Assert.assertEquals(dateStr, "2023-08-08");
}
@Test
void testDayDateList() {
String startDate = "2023-07-29";
String endDate = "2023-08-03";
List<String> actualDateList = DateUtils.getDateList(startDate, endDate, Constants.DAY);
List<String> expectedDateList = Lists.newArrayList("2023-07-29", "2023-07-30",
"2023-07-31", "2023-08-01", "2023-08-02", "2023-08-03");
Assertions.assertEquals(actualDateList, expectedDateList);
}
@Test
void testWeekDateList() {
String startDate = "2023-10-30";
String endDate = "2023-11-13";
List<String> actualDateList = DateUtils.getDateList(startDate, endDate, Constants.WEEK);
List<String> expectedDateList = Lists.newArrayList("2023-10-30", "2023-11-06",
"2023-11-13");
Assertions.assertEquals(actualDateList, expectedDateList);
}
@Test
void testMonthDateList() {
String startDate = "2023-07-01";
String endDate = "2023-10-01";
List<String> actualDateList = DateUtils.getDateList(startDate, endDate, Constants.MONTH);
List<String> expectedDateList = Lists.newArrayList("2023-07-01", "2023-08-01",
"2023-09-01", "2023-10-01");
Assertions.assertEquals(actualDateList, expectedDateList);
}
}