Class DayOfMonth

java.lang.Object
cloud.opencode.base.date.extra.DayOfMonth
All Implemented Interfaces:
Serializable, Comparable<DayOfMonth>, TemporalAccessor, TemporalAdjuster

public final class DayOfMonth extends Object implements TemporalAccessor, TemporalAdjuster, Comparable<DayOfMonth>, Serializable
DayOfMonth class representing a day within a month (1-31) 月份中的天,表示月份中的一天(1-31)

This class represents a day-of-month value, independent of any particular month or year. When combined with a specific month/year, the validity of the day-of-month is checked.

此类表示月份中的天值,独立于任何特定的月份或年份。 当与特定月份/年份组合时,会检查日期的有效性。

Features | 主要功能:

  • Day-of-month representation (1-31) - 月中天数表示(1-31)
  • Validation for specific year-months - 特定年月验证
  • Combine with YearMonth to create LocalDate - 与YearMonth组合创建LocalDate
  • TemporalAccessor and TemporalAdjuster implementations - 实现TemporalAccessor和TemporalAdjuster

Usage Examples | 使用示例:

DayOfMonth day = DayOfMonth.of(15);
DayOfMonth first = DayOfMonth.first();
boolean valid = day.isValidFor(YearMonth.of(2024, 2));  // true for day 15 in Feb 2024
LocalDate date = day.atYearMonth(YearMonth.of(2024, 3));  // 2024-03-15

Security | 安全性:

  • Thread-safe: Yes (immutable, cached instances) - 线程安全: 是(不可变,缓存实例)
  • 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 DayOfMonth of(int dayOfMonth)
      Creates a DayOfMonth from a value (1-31) 从值(1-31)创建DayOfMonth
      Parameters:
      dayOfMonth - the day of month (1-31) | 月份中的天(1-31)
      Returns:
      the DayOfMonth | DayOfMonth实例
      Throws:
      OpenDateException - if the value is out of range | 如果值超出范围则抛出异常
    • first

      public static DayOfMonth first()
      Gets the first day of month (1) 获取月份的第一天(1)
      Returns:
      day 1 | 第1天
    • from

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

      public static DayOfMonth now()
      Gets the current day of month 获取当前月份中的天
      Returns:
      the current DayOfMonth | 当前的DayOfMonth
    • getValue

      public int getValue()
      Gets the day-of-month value (1-31) 获取月份中的天值(1-31)
      Returns:
      the day value | 天值
    • isValidFor

      public boolean isValidFor(YearMonth yearMonth)
      Checks if this day is valid for the given YearMonth 检查此天在给定YearMonth中是否有效
      Parameters:
      yearMonth - the year-month | 年月
      Returns:
      true if valid | 如果有效返回true
    • isValidFor

      public boolean isValidFor(Month month, boolean leapYear)
      Checks if this day is valid for the given month in a leap year 检查此天在闰年的给定月份中是否有效
      Parameters:
      month - the month | 月份
      leapYear - whether it's a leap year | 是否为闰年
      Returns:
      true if valid | 如果有效返回true
    • isFirst

      public boolean isFirst()
      Checks if this is the first day of month 检查是否为月份的第一天
      Returns:
      true if day is 1 | 如果是第1天返回true
    • isPossibleLastDay

      public boolean isPossibleLastDay()
      Checks if this could be the last day of any month 检查是否可能是某月的最后一天
      Returns:
      true if day is 28, 29, 30, or 31 | 如果天数是28、29、30或31返回true
    • atYearMonth

      public LocalDate atYearMonth(YearMonth yearMonth)
      Combines this day with a YearMonth to create a LocalDate 将此天与YearMonth组合创建LocalDate
      Parameters:
      yearMonth - the year-month | 年月
      Returns:
      the resulting date | 结果日期
      Throws:
      OpenDateException - if this day is not valid for the given month | 如果此天在给定月份无效则抛出异常
    • atYearMonth

      public LocalDate atYearMonth(int year, int month)
      Combines this day with year and month to create a LocalDate 将此天与年和月组合创建LocalDate
      Parameters:
      year - the year | 年
      month - the month | 月
      Returns:
      the resulting date | 结果日期
    • atYearMonth

      public LocalDate atYearMonth(int year, Month month)
      Combines this day with year and Month to create a LocalDate 将此天与年和Month组合创建LocalDate
      Parameters:
      year - the year | 年
      month - the Month | 月份
      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<DayOfMonth> query()
      Gets a query for extracting DayOfMonth from a temporal 获取从时间对象提取DayOfMonth的查询
      Returns:
      the query | 查询
    • compareTo

      public int compareTo(DayOfMonth other)
      Specified by:
      compareTo in interface Comparable<DayOfMonth>
    • 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