(common)(fix):add recent date calculate if period is year (#625)

This commit is contained in:
Scott
2024-01-15 15:56:09 +08:00
committed by GitHub
parent e7d654f150
commit a6818fb6ff

View File

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