From 8ac446e2287eb16dd0a65532a7f657a23c1ac971 Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Tue, 24 Dec 2024 17:39:42 +0800 Subject: [PATCH] =?UTF-8?q?YearQuarter=20=E6=96=B0=E5=A2=9E=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plusone/commons/time/YearQuarter.java | 32 ++++++++++++++++--- 1 file changed, 28 insertions(+), 4 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 966c7b9..7fd4885 100644 --- a/src/main/java/xyz/zhouxy/plusone/commons/time/YearQuarter.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/time/YearQuarter.java @@ -59,7 +59,7 @@ public final class YearQuarter implements Comparable, Serializable this.lastDate = quarter.lastMonthDay().atYear(year); } - // #region - StaticFactoryMethod + // #region - StaticFactory /** * 根据指定年份与季度,创建 {@link YearQuarter} 实例 @@ -186,7 +186,7 @@ public final class YearQuarter implements Comparable, Serializable // #region - computes public YearQuarter plusQuarters(long quartersToAdd) { // TODO 单元测试 - if (quartersToAdd == 0) { + if (quartersToAdd == 0L) { return this; } long quarterCount = this.year * 4L + (this.quarter.getValue() - 1); @@ -200,8 +200,16 @@ public final class YearQuarter implements Comparable, Serializable return plusQuarters(-quartersToAdd); } + public YearQuarter nextQuarter() { // TODO 单元测试 + return plusQuarters(1L); + } + + public YearQuarter lastQuarter() { // TODO 单元测试 + return minusQuarters(1L); + } + public YearQuarter plusYears(long yearsToAdd) { // TODO 单元测试 - if (yearsToAdd == 0) { + if (yearsToAdd == 0L) { return this; } int newYear = YEAR.checkValidIntValue(this.year + yearsToAdd); // safe overflow @@ -212,6 +220,14 @@ public final class YearQuarter implements Comparable, Serializable return plusYears(-yearsToAdd); } + public YearQuarter nextYear() { + return plusYears(1L); + } + + public YearQuarter lastYear() { + return minusYears(1L); + } + // #endregion // #region - hashCode & equals @@ -235,7 +251,7 @@ public final class YearQuarter implements Comparable, Serializable // #endregion - // #region - compareTo + // #region - compare @Override public int compareTo(YearQuarter other) { @@ -254,6 +270,14 @@ public final class YearQuarter implements Comparable, Serializable return this.compareTo(other) > 0; } + public static YearQuarter min(YearQuarter yearQuarter1, YearQuarter yearQuarter2) { // TODO 单元测试 + return yearQuarter1.compareTo(yearQuarter2) <= 0 ? yearQuarter1 : yearQuarter2; + } + + public static YearQuarter max(YearQuarter yearQuarter1, YearQuarter yearQuarter2) { // TODO 单元测试 + return yearQuarter1.compareTo(yearQuarter2) >= 0 ? yearQuarter1 : yearQuarter2; + } + // #endregion // #region - toString