Class DayOfYear
java.lang.Object
cloud.opencode.base.date.extra.DayOfYear
- All Implemented Interfaces:
Serializable, Comparable<DayOfYear>, TemporalAccessor, TemporalAdjuster
public final class DayOfYear
extends Object
implements TemporalAccessor, TemporalAdjuster, Comparable<DayOfYear>, Serializable
DayOfYear class representing a day within a year (1-366)
年份中的天,表示年份中的一天(1-366)
This class represents a day-of-year value, independent of any particular year. When combined with a specific year, the validity of the day-of-year is checked.
此类表示年份中的天值,独立于任何特定的年份。 当与特定年份组合时,会检查日期的有效性。
Features | 主要功能:
- Day-of-year representation (1-366) - 年中天数表示(1-366)
- Validation for specific years - 特定年份验证
- Combine with year to create LocalDate - 与年份组合创建LocalDate
- TemporalAccessor and TemporalAdjuster implementations - 实现TemporalAccessor和TemporalAdjuster
Usage Examples | 使用示例:
DayOfYear day = DayOfYear.of(100);
DayOfYear first = DayOfYear.first();
boolean valid = day.isValidFor(Year.of(2024)); // true
LocalDate date = day.atYear(2024); // 2024-04-09
Security | 安全性:
- Thread-safe: Yes (immutable) - 线程安全: 是(不可变)
- Null-safe: Yes (with explicit null checks) - 空值安全: 是(有明确的空值检查)
- Since:
- JDK 25, opencode-base-date V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionadjustInto(Temporal temporal) atYear(int year) Combines this day with a year value to create a LocalDate 将此天与年份值组合创建LocalDateCombines this day with a Year to create a LocalDate 将此天与Year组合创建LocalDateintbooleanstatic DayOfYearfirst()Gets the first day of year (1) 获取年份的第一天(1)static DayOfYearfrom(TemporalAccessor temporal) Gets a DayOfYear from a TemporalAccessor 从TemporalAccessor获取DayOfYearlonggetLong(TemporalField field) intgetValue()Gets the day-of-year value (1-366) 获取年份中的天值(1-366)inthashCode()booleanisFirst()Checks if this is the first day of year 检查是否为年份的第一天booleanChecks if this is day 366 (leap year only) 检查是否为第366天(仅闰年)booleanisSupported(TemporalField field) booleanisValidFor(int year) Checks if this day is valid for the given year 检查此天在给定年份中是否有效booleanisValidFor(Year year) Checks if this day is valid for the given year 检查此天在给定年份中是否有效booleanChecks if this day is valid for both leap and non-leap years 检查此天在闰年和非闰年中是否都有效static DayOfYearlastOf(int year) Gets the last day of year for the given year 获取给定年份的最后一天static DayOfYearnow()Gets the current day of year 获取当前年份中的天static DayOfYearof(int dayOfYear) Creates a DayOfYear from a value (1-366) 从值(1-366)创建DayOfYearstatic TemporalQuery<DayOfYear> query()Gets a query for extracting DayOfYear from a temporal 获取从时间对象提取DayOfYear的查询range(TemporalField field) toString()Methods inherited from interface TemporalAccessor
get, query
-
Method Details
-
of
Creates a DayOfYear from a value (1-366) 从值(1-366)创建DayOfYear- Parameters:
dayOfYear- the day of year (1-366) | 年份中的天(1-366)- Returns:
- the DayOfYear | DayOfYear实例
- Throws:
OpenDateException- if the value is out of range | 如果值超出范围则抛出异常
-
first
-
lastOf
Gets the last day of year for the given year 获取给定年份的最后一天- Parameters:
year- the year | 年份- Returns:
- day 365 or 366 | 第365或366天
-
from
Gets a DayOfYear from a TemporalAccessor 从TemporalAccessor获取DayOfYear- Parameters:
temporal- the temporal accessor | 时间访问器- Returns:
- the DayOfYear | DayOfYear实例
-
now
Gets the current day of year 获取当前年份中的天- Returns:
- the current DayOfYear | 当前的DayOfYear
-
getValue
public int getValue()Gets the day-of-year value (1-366) 获取年份中的天值(1-366)- Returns:
- the day value | 天值
-
isValidFor
Checks if this day is valid for the given year 检查此天在给定年份中是否有效- Parameters:
year- the year | 年份- Returns:
- true if valid | 如果有效返回true
-
isValidFor
public boolean isValidFor(int year) Checks if this day is valid for the given year 检查此天在给定年份中是否有效- Parameters:
year- the year | 年份- Returns:
- true if valid | 如果有效返回true
-
isValidForAllYears
public boolean isValidForAllYears()Checks if this day is valid for both leap and non-leap years 检查此天在闰年和非闰年中是否都有效- Returns:
- true if day is 1-365 | 如果天数是1-365返回true
-
isFirst
public boolean isFirst()Checks if this is the first day of year 检查是否为年份的第一天- Returns:
- true if day is 1 | 如果是第1天返回true
-
isLeapDay
public boolean isLeapDay()Checks if this is day 366 (leap year only) 检查是否为第366天(仅闰年)- Returns:
- true if day is 366 | 如果是第366天返回true
-
atYear
Combines this day with a Year to create a LocalDate 将此天与Year组合创建LocalDate- Parameters:
year- the year | 年份- Returns:
- the resulting date | 结果日期
- Throws:
OpenDateException- if this day is not valid for the given year | 如果此天在给定年份无效则抛出异常
-
atYear
Combines this day with a year value to create a LocalDate 将此天与年份值组合创建LocalDate- Parameters:
year- the year | 年份- Returns:
- the resulting date | 结果日期
-
isSupported
- Specified by:
isSupportedin interfaceTemporalAccessor
-
getLong
- Specified by:
getLongin interfaceTemporalAccessor
-
range
- Specified by:
rangein interfaceTemporalAccessor
-
adjustInto
- Specified by:
adjustIntoin interfaceTemporalAdjuster
-
query
Gets a query for extracting DayOfYear from a temporal 获取从时间对象提取DayOfYear的查询- Returns:
- the query | 查询
-
compareTo
- Specified by:
compareToin interfaceComparable<DayOfYear>
-
equals
-
hashCode
-
toString
-