龚焕茏
2024-03-08 0fa29e0dc36990e5826be5f6d1bcc84c9a13201a
dujy-admin/src/test/java/org/dromara/test/DemoUnitTest.java
@@ -5,6 +5,8 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.time.LocalDate;
import java.time.Month;
import java.util.concurrent.TimeUnit;
/**
@@ -67,4 +69,34 @@
        System.out.println("@AfterAll ==================");
    }
    /**
     * @Description TODO 获取本季度的第一天或最后一天
     * @Param: [today, isFirst: true 表示开始时间,false表示结束时间]
     * @return: java.lang.String
     */
    public static String getStartOrEndDayOfQuarter(LocalDate today, Boolean isFirst) {
        LocalDate resDate = LocalDate.now();
        if (today == null) {
            today = resDate;
        }
        Month month = today.getMonth();
        Month firstMonthOfQuarter = month.firstMonthOfQuarter();
        Month endMonthOfQuarter = Month.of(firstMonthOfQuarter.getValue() + 2);
        if (isFirst) {
            resDate = LocalDate.of(today.getYear(), firstMonthOfQuarter, 1);
        } else {
            resDate = LocalDate.of(today.getYear(), endMonthOfQuarter, endMonthOfQuarter.length(today.isLeapYear()));
        }
        return resDate.toString();
    }
    public static void main(String[] args) {
        System.out.println(getStartOrEndDayOfQuarter(LocalDate.parse("2024-05-04"), false));
        System.out.println(getStartOrEndDayOfQuarter(LocalDate.parse("2024-06-04"), false));
        System.out.println(getStartOrEndDayOfQuarter(LocalDate.parse("2024-07-04"), false));
        System.out.println(getStartOrEndDayOfQuarter(LocalDate.parse("2024-01-04"), false));
        System.out.println(getStartOrEndDayOfQuarter(LocalDate.parse("2024-02-04"), false));
    }
}