mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-13 13:07:32 +00:00
(common)(fix):add quarter date period (#632)
This commit is contained in:
@@ -4,6 +4,7 @@ public enum DatePeriodEnum {
|
|||||||
DAY("日"),
|
DAY("日"),
|
||||||
WEEK("周"),
|
WEEK("周"),
|
||||||
MONTH("月"),
|
MONTH("月"),
|
||||||
|
QUARTER("季度"),
|
||||||
YEAR("年");
|
YEAR("年");
|
||||||
private String chName;
|
private String chName;
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import java.text.SimpleDateFormat;
|
|||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.time.temporal.ChronoField;
|
||||||
|
import java.time.temporal.TemporalAdjuster;
|
||||||
import java.time.temporal.TemporalAdjusters;
|
import java.time.temporal.TemporalAdjusters;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
@@ -91,6 +93,19 @@ public class DateUtils {
|
|||||||
result = result.with(TemporalAdjusters.firstDayOfMonth());
|
result = result.with(TemporalAdjusters.firstDayOfMonth());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case QUARTER:
|
||||||
|
result = currentDate.minusMonths(intervalDay * 3L);
|
||||||
|
if (intervalDay == 0) {
|
||||||
|
TemporalAdjuster firstDayOfQuarter = temporal -> {
|
||||||
|
LocalDate tempDate = LocalDate.from(temporal);
|
||||||
|
int month = tempDate.get(ChronoField.MONTH_OF_YEAR);
|
||||||
|
int firstMonthOfQuarter = ((month - 1) / 3) * 3 + 1;
|
||||||
|
return tempDate.with(ChronoField.MONTH_OF_YEAR, firstMonthOfQuarter)
|
||||||
|
.with(TemporalAdjusters.firstDayOfMonth());
|
||||||
|
};
|
||||||
|
result = result.with(firstDayOfQuarter);
|
||||||
|
}
|
||||||
|
break;
|
||||||
case YEAR:
|
case YEAR:
|
||||||
result = currentDate.minusYears(intervalDay);
|
result = currentDate.minusYears(intervalDay);
|
||||||
if (intervalDay == 0) {
|
if (intervalDay == 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user