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 Details

    • of

      public static DayOfYear of(int dayOfYear)
      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

      public static DayOfYear first()
      Gets the first day of year (1) 获取年份的第一天(1)
      Returns:
      day 1 | 第1天
    • lastOf

      public static DayOfYear lastOf(int year)
      Gets the last day of year for the given year 获取给定年份的最后一天
      Parameters:
      year - the year | 年份
      Returns:
      day 365 or 366 | 第365或366天
    • from

      public static DayOfYear from(TemporalAccessor temporal)
      Gets a DayOfYear from a TemporalAccessor 从TemporalAccessor获取DayOfYear
      Parameters:
      temporal - the temporal accessor | 时间访问器
      Returns:
      the DayOfYear | DayOfYear实例
    • now

      public static 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

      public boolean isValidFor(Year year)
      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

      public LocalDate atYear(Year year)
      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

      public LocalDate atYear(int year)
      Combines this day with a year value to create a LocalDate 将此天与年份值组合创建LocalDate
      Parameters:
      year - the year | 年份
      Returns:
      the resulting date | 结果日期
    • isSupported

      public boolean isSupported(TemporalField field)
      Specified by:
      isSupported in interface TemporalAccessor
    • getLong

      public long getLong(TemporalField field)
      Specified by:
      getLong in interface TemporalAccessor
    • range

      public ValueRange range(TemporalField field)
      Specified by:
      range in interface TemporalAccessor
    • adjustInto

      public Temporal adjustInto(Temporal temporal)
      Specified by:
      adjustInto in interface TemporalAdjuster
    • query

      public static TemporalQuery<DayOfYear> query()
      Gets a query for extracting DayOfYear from a temporal 获取从时间对象提取DayOfYear的查询
      Returns:
      the query | 查询
    • compareTo

      public int compareTo(DayOfYear other)
      Specified by:
      compareTo in interface Comparable<DayOfYear>
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object