Enum Class Quarter
- All Implemented Interfaces:
Serializable, Comparable<Quarter>, Constable, TemporalAccessor, TemporalQuery<Quarter>
Quarter Enum representing the four quarters of a year
季度枚举,表示一年中的四个季度
This enum represents the four quarters of a year: Q1 (Jan-Mar), Q2 (Apr-Jun), Q3 (Jul-Sep), and Q4 (Oct-Dec).
此枚举表示一年中的四个季度:Q1(1-3月)、Q2(4-6月)、Q3(7-9月)、Q4(10-12月)。
Features | 主要功能:
- Get quarter from value (1-4) - 从值(1-4)获取季度
- Get quarter from month - 从月份获取季度
- Get first/last month of quarter - 获取季度的第一个/最后一个月
- Calculate quarter length in days - 计算季度天数
Usage Examples | 使用示例:
// Get quarter from value
Quarter q1 = Quarter.of(1); // Q1
// Get quarter from month
Quarter q2 = Quarter.ofMonth(5); // Q2 (May is in Q2)
Quarter q3 = Quarter.from(Month.AUGUST); // Q3
// Get month information
int firstMonth = Quarter.Q1.firstMonth(); // 1 (January)
int lastMonth = Quarter.Q1.lastMonth(); // 3 (March)
// Calculate length
int days = Quarter.Q1.length(false); // 90 days (non-leap year)
int daysLeap = Quarter.Q1.length(true); // 91 days (leap year)
Security | 安全性:
- Thread-safe: Yes (enum is inherently thread-safe) - 线程安全: 是(枚举本身是线程安全的)
- Immutable: Yes - 不可变: 是
- Since:
- JDK 25, opencode-base-date V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class Enum
Enum.EnumDesc<E> -
Enum Constant Summary
Enum Constants -
Method Summary
Modifier and TypeMethodDescriptionbooleancontains(int month) Checks if the given month is in this quarter 检查给定月份是否在此季度内booleanChecks if the given Month is in this quarter 检查给定Month是否在此季度内intGets the first month of this quarter (1, 4, 7, or 10) 获取季度的第一个月(1, 4, 7, 或 10)Gets the first Month enum of this quarter 获取季度的第一个Month枚举static QuarterGets the Quarter from a Month enum 从Month枚举获取季度static Quarterfrom(TemporalAccessor temporal) Gets the Quarter from a TemporalAccessor 从TemporalAccessor获取季度longgetLong(TemporalField field) intgetValue()Gets the quarter value (1-4) 获取季度值(1-4)booleanisSupported(TemporalField field) intGets the last month of this quarter (3, 6, 9, or 12) 获取季度的最后一个月(3, 6, 9, 或 12)Gets the last Month enum of this quarter 获取季度的最后一个Month枚举intlength(boolean leapYear) Gets the length of this quarter in days 获取季度的天数minus(int quarters) Subtracts quarters from this quarter 在此季度基础上减季度数next()Gets the next quarter 获取下一个季度static Quarterof(int quarter) Gets the Quarter from a numeric value (1-4) 从数值(1-4)获取季度static QuarterofMonth(int month) Gets the Quarter from a month value (1-12) 从月份值(1-12)获取季度plus(int quarters) Adds quarters to this quarter 在此季度基础上加季度数previous()Gets the previous quarter 获取上一个季度static TemporalQuery<Quarter> query()Gets a query for extracting the Quarter from a temporal 获取从时间对象提取季度的查询queryFrom(TemporalAccessor temporal) range(TemporalField field) static QuarterReturns the enum constant of this class with the specified name.static Quarter[]values()Returns an array containing the constants of this enum class, in the order they are declared.Methods inherited from class Enum
clone, compareTo, describeConstable, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOfMethods inherited from interface TemporalAccessor
get, query
-
Enum Constant Details
-
Q1
First quarter: January, February, March 第一季度:一月、二月、三月 -
Q2
Second quarter: April, May, June 第二季度:四月、五月、六月 -
Q3
Third quarter: July, August, September 第三季度:七月、八月、九月 -
Q4
Fourth quarter: October, November, December 第四季度:十月、十一月、十二月
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum class has no constant with the specified nameNullPointerException- if the argument is null
-
of
Gets the Quarter from a numeric value (1-4) 从数值(1-4)获取季度- Parameters:
quarter- the quarter value from 1 to 4 | 季度值,范围1到4- Returns:
- the Quarter instance | 季度实例
- Throws:
OpenDateException- if the value is out of range | 如果值超出范围则抛出异常
-
ofMonth
Gets the Quarter from a month value (1-12) 从月份值(1-12)获取季度- Parameters:
month- the month value from 1 to 12 | 月份值,范围1到12- Returns:
- the Quarter containing the specified month | 包含指定月份的季度
- Throws:
OpenDateException- if the month is out of range | 如果月份超出范围则抛出异常
-
from
Gets the Quarter from a Month enum 从Month枚举获取季度- Parameters:
month- the Month enum | Month枚举- Returns:
- the Quarter containing the specified month | 包含指定月份的季度
- Throws:
NullPointerException- if month is null | 如果月份为null则抛出异常
-
from
Gets the Quarter from a TemporalAccessor 从TemporalAccessor获取季度- Parameters:
temporal- the temporal accessor | 时间访问器- Returns:
- the Quarter | 季度
- Throws:
OpenDateException- if unable to convert | 如果无法转换则抛出异常
-
getValue
public int getValue()Gets the quarter value (1-4) 获取季度值(1-4)- Returns:
- the quarter value from 1 to 4 | 季度值,范围1到4
-
firstMonth
public int firstMonth()Gets the first month of this quarter (1, 4, 7, or 10) 获取季度的第一个月(1, 4, 7, 或 10)- Returns:
- the first month value | 第一个月的值
-
lastMonth
public int lastMonth()Gets the last month of this quarter (3, 6, 9, or 12) 获取季度的最后一个月(3, 6, 9, 或 12)- Returns:
- the last month value | 最后一个月的值
-
firstMonthOfQuarter
Gets the first Month enum of this quarter 获取季度的第一个Month枚举- Returns:
- the first Month | 第一个月
-
lastMonthOfQuarter
Gets the last Month enum of this quarter 获取季度的最后一个Month枚举- Returns:
- the last Month | 最后一个月
-
length
public int length(boolean leapYear) Gets the length of this quarter in days 获取季度的天数- Parameters:
leapYear- whether it's a leap year | 是否为闰年- Returns:
- the number of days in this quarter | 季度天数
-
next
Gets the next quarter 获取下一个季度- Returns:
- the next quarter (Q1 -> Q2 -> Q3 -> Q4 -> Q1) | 下一个季度
-
previous
Gets the previous quarter 获取上一个季度- Returns:
- the previous quarter (Q4 -> Q3 -> Q2 -> Q1 -> Q4) | 上一个季度
-
plus
Adds quarters to this quarter 在此季度基础上加季度数- Parameters:
quarters- the quarters to add | 要加的季度数- Returns:
- the resulting quarter | 结果季度
-
minus
Subtracts quarters from this quarter 在此季度基础上减季度数- Parameters:
quarters- the quarters to subtract | 要减的季度数- Returns:
- the resulting quarter | 结果季度
-
isSupported
- Specified by:
isSupportedin interfaceTemporalAccessor
-
getLong
- Specified by:
getLongin interfaceTemporalAccessor
-
range
- Specified by:
rangein interfaceTemporalAccessor
-
queryFrom
- Specified by:
queryFromin interfaceTemporalQuery<Quarter>
-
query
Gets a query for extracting the Quarter from a temporal 获取从时间对象提取季度的查询- Returns:
- the quarter query | 季度查询
-
contains
public boolean contains(int month) Checks if the given month is in this quarter 检查给定月份是否在此季度内- Parameters:
month- the month to check | 要检查的月份- Returns:
- true if the month is in this quarter | 如果月份在此季度内返回true
-
contains
Checks if the given Month is in this quarter 检查给定Month是否在此季度内- Parameters:
month- the Month to check | 要检查的月份- Returns:
- true if the Month is in this quarter | 如果月份在此季度内返回true
-