From a6818fb6ffae077dacb688457863ffe276aaec8c Mon Sep 17 00:00:00 2001 From: Scott Date: Mon, 15 Jan 2024 15:56:09 +0800 Subject: [PATCH] (common)(fix):add recent date calculate if period is year (#625) --- .../supersonic/common/util/DateModeUtils.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/common/src/main/java/com/tencent/supersonic/common/util/DateModeUtils.java b/common/src/main/java/com/tencent/supersonic/common/util/DateModeUtils.java index 571b6cb49..f3c4f93b7 100644 --- a/common/src/main/java/com/tencent/supersonic/common/util/DateModeUtils.java +++ b/common/src/main/java/com/tencent/supersonic/common/util/DateModeUtils.java @@ -7,6 +7,7 @@ import static com.tencent.supersonic.common.pojo.Constants.DAY_FORMAT; import static com.tencent.supersonic.common.pojo.Constants.MONTH; import static com.tencent.supersonic.common.pojo.Constants.MONTH_FORMAT; import static com.tencent.supersonic.common.pojo.Constants.WEEK; +import static com.tencent.supersonic.common.pojo.Constants.YEAR; import com.google.common.base.Strings; import com.tencent.supersonic.common.pojo.DateConf; @@ -304,15 +305,18 @@ public class DateModeUtils { return String.format("(%s >= '%s' and %s <= '%s')", sysDateCol, dateMin, sysDateCol, dateMax); } - if (MONTH.equalsIgnoreCase(dateInfo.getPeriod())) { - LocalDate dateMax = LocalDate.now().minusDays(1); - //return generateMonthSql(dateMax, unit.longValue(), DAY_FORMAT); - return recentMonthStr(dateMax, unit.longValue(), MONTH_FORMAT); - } if (WEEK.equalsIgnoreCase(dateInfo.getPeriod())) { LocalDate dateMax = LocalDate.now().minusDays(1); return recentWeekStr(dateMax, unit.longValue()); } + if (MONTH.equalsIgnoreCase(dateInfo.getPeriod())) { + LocalDate dateMax = LocalDate.now().minusDays(1); + return recentMonthStr(dateMax, unit.longValue(), MONTH_FORMAT); + } + if (YEAR.equalsIgnoreCase(dateInfo.getPeriod())) { + LocalDate dateMax = LocalDate.now().minusDays(1); + return recentMonthStr(dateMax, unit.longValue() * 12, MONTH_FORMAT); + } return String.format("(%s >= '%s' and %s <= '%s')", sysDateCol, LocalDate.now().minusDays(2), sysDateCol, LocalDate.now().minusDays(1));