public final class DayOfMonth extends java.lang.Object implements Calendrical, java.lang.Comparable<DayOfMonth>, DateAdjuster, CalendricalMatcher, java.io.Serializable
DayOfMonth is an immutable time field that can only store a day-of-month. It is a type-safe way of representing a day-of-month in an application.
Static factory methods allow you to construct instances. The day-of-month may be queried using getValue().
DayOfMonth is immutable and thread-safe.
Modifier and Type | Method and Description |
---|---|
LocalDate |
adjustDate(LocalDate date)
Adjusts a date to have the value of this day-of-month, returning a new date.
|
LocalDate |
adjustDate(LocalDate date,
DateResolver resolver)
Adjusts a date to have the value of this day-of-month, using a resolver
to handle the case when the day-of-month is invalid for the year and month.
|
int |
compareTo(DayOfMonth otherDayOfMonth)
Compares this day-of-month instance to another.
|
static DayOfMonth |
dayOfMonth(Calendrical calendrical)
Obtains an instance of
DayOfMonth from a calendrical. |
static DayOfMonth |
dayOfMonth(int dayOfMonth)
Obtains an instance of
DayOfMonth from a value. |
boolean |
equals(java.lang.Object otherDayOfMonth)
Is this instance equal to that specified, evaluating the day-of-month.
|
<T> T |
get(CalendricalRule<T> rule)
Gets the value of the specified calendrical rule.
|
int |
getValue()
Gets the day-of-month value.
|
int |
hashCode()
A hash code for the day-of-month object.
|
boolean |
matchesCalendrical(Calendrical calendrical)
Checks if the day-of-month extracted from the calendrical matches this.
|
static DateTimeFieldRule<java.lang.Integer> |
rule()
Gets the rule that defines how the day-of-month field operates.
|
java.lang.String |
toString()
A string describing the day-of-month object.
|
public static DateTimeFieldRule<java.lang.Integer> rule()
The rule provides access to the minimum and maximum values, and a generic way to access values within a calendrical.
public static DayOfMonth dayOfMonth(int dayOfMonth)
DayOfMonth
from a value.
A day-of-month object represents one of the 31 days of the month, from 1 to 31.
dayOfMonth
- the day-of-month to represent, from 1 to 31IllegalCalendarFieldValueException
- if the dayOfMonth is invalidpublic static DayOfMonth dayOfMonth(Calendrical calendrical)
DayOfMonth
from a calendrical.
This can be used extract the day-of-month value directly from any implementation
of Calendrical
, including those in other calendar systems.
calendrical
- the calendrical to extract from, not nullUnsupportedRuleException
- if the day-of-month cannot be obtainedpublic <T> T get(CalendricalRule<T> rule)
This method queries the value of the specified calendrical rule.
If the value cannot be returned for the rule from this instance then
null
will be returned.
get
in interface Calendrical
rule
- the rule to use, not nullpublic int getValue()
public boolean matchesCalendrical(Calendrical calendrical)
matchesCalendrical
in interface CalendricalMatcher
calendrical
- the calendrical to match, not nullpublic LocalDate adjustDate(LocalDate date)
If the day-of-month is invalid for the year and month then an exception is thrown.
This instance is immutable and unaffected by this method call.
adjustDate
in interface DateAdjuster
date
- the date to be adjusted, not nullpublic LocalDate adjustDate(LocalDate date, DateResolver resolver)
This instance is immutable and unaffected by this method call.
date
- the date to be adjusted, not nullresolver
- the date resolver to use, not nullIllegalCalendarFieldValueException
- if the date cannot be resolved using the resolverpublic int compareTo(DayOfMonth otherDayOfMonth)
compareTo
in interface java.lang.Comparable<DayOfMonth>
otherDayOfMonth
- the other day-of-month instance, not nulljava.lang.NullPointerException
- if otherDayOfMonth is nullpublic boolean equals(java.lang.Object otherDayOfMonth)
equals
in class java.lang.Object
otherDayOfMonth
- the other day-of-month instance, null returns falsepublic int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object