From 322ecf4db8094855dbbae3806357fe4ea8b958d9 Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Mon, 2 Sep 2024 17:09:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20YearQuarter=20=E7=9A=84?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plusone/commons/time/YearQuarter.java | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/main/java/xyz/zhouxy/plusone/commons/time/YearQuarter.java b/src/main/java/xyz/zhouxy/plusone/commons/time/YearQuarter.java index de30339..8390251 100644 --- a/src/main/java/xyz/zhouxy/plusone/commons/time/YearQuarter.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/time/YearQuarter.java @@ -31,14 +31,6 @@ public final class YearQuarter implements Comparable, Serializable /** 季度结束日期 */ private final LocalDate lastDate; - private YearQuarter(int year, int quarter) { - Preconditions.checkNotNull(quarter, "Quarter can not be null."); - this.year = year; - this.quarter = Quarter.of(quarter); - this.firstDate = this.quarter.firstMonthDay().atYear(year); - this.lastDate = this.quarter.lastMonthDay().atYear(year); - } - private YearQuarter(int year, @Nonnull Quarter quarter) { Preconditions.checkNotNull(quarter, "Quarter can not be null."); this.year = year; @@ -47,6 +39,17 @@ public final class YearQuarter implements Comparable, Serializable this.lastDate = quarter.lastMonthDay().atYear(year); } + /** + * 根据指定年份与季度,创建 {@link YearQuarter} 实例 + * + * @param year 年份 + * @param quarter 季度 + * @return {@link YearQuarter} 实例 + */ + public static YearQuarter of(int year, int quarter) { + return of(year, Quarter.of(quarter)); + } + /** * 根据指定年份与季度,创建 {@link YearQuarter} 实例 * @@ -65,7 +68,7 @@ public final class YearQuarter implements Comparable, Serializable * @return {@link YearQuarter} 实例 */ public static YearQuarter of(@Nonnull LocalDate date) { - return new YearQuarter(date.getYear(), Quarter.fromMonth(date.getMonth())); + return of(date.getYear(), Quarter.fromMonth(date.getMonth())); } /** @@ -202,7 +205,7 @@ public final class YearQuarter implements Comparable, Serializable public int compareTo(YearQuarter other) { int cmp = (this.year - other.year); if (cmp == 0) { - cmp = (this.quarter.compareTo(other.quarter)); + cmp = this.quarter.compareTo(other.quarter); } return cmp; }