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