public final class DayOfYear extends java.lang.Object implements Calendrical, java.lang.Comparable<DayOfYear>, DateAdjuster, CalendricalMatcher, java.io.Serializable
DayOfYear is an immutable time field that can only store a day-of-year. It is a type-safe way of representing a day-of-year in an application.
Static factory methods allow you to construct instances. The day-of-year may be queried using getValue().
DayOfYear 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-year, returning a new date.
|
LocalDate |
atYear(int year)
Returns a date formed from this day-of-year at the specified year.
|
LocalDate |
atYear(Year year)
Returns a date formed from this day-of-year at the specified year.
|
int |
compareTo(DayOfYear otherDayOfYear)
Compares this day-of-year instance to another.
|
static DayOfYear |
dayOfYear(Calendrical calendrical)
Obtains an instance of
DayOfYear from a calendrical. |
static DayOfYear |
dayOfYear(int dayOfYear)
Obtains an instance of
DayOfYear from a value. |
boolean |
equals(java.lang.Object otherDayOfYear)
Is this instance equal to that specified, evaluating the day-of-year.
|
<T> T |
get(CalendricalRule<T> rule)
Gets the value of the specified calendrical rule.
|
int |
getValue()
Gets the day-of-year value.
|
int |
hashCode()
A hash code for the day-of-year object.
|
boolean |
isValid(int year)
Checks if this day-of-year is valid for the specified year.
|
boolean |
isValid(Year year)
Checks if this day-of-year is valid for the specified year.
|
boolean |
matchesCalendrical(Calendrical calendrical)
Checks if the day-of-year extracted from the calendrical matches this.
|
static DateTimeFieldRule<java.lang.Integer> |
rule()
Gets the rule that defines how the day-of-year field operates.
|
java.lang.String |
toString()
A string describing the day-of-year 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 DayOfYear dayOfYear(int dayOfYear)
DayOfYear
from a value.
A day-of-year object represents one of the 366 days of the year, from 1 to 366.
dayOfYear
- the day-of-year to represent, from 1 to 366IllegalCalendarFieldValueException
- if the dayOfYear is invalidpublic static DayOfYear dayOfYear(Calendrical calendrical)
DayOfYear
from a calendrical.
This can be used extract the day-of-year 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-year 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-year 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 nullIllegalCalendarFieldValueException
- if the day-of-year is invalid for the input yearpublic boolean isValid(Year year)
year
- the year to validate against, not nullpublic boolean isValid(int year)
year
- the year to validate against, from MIN_YEAR to MAX_YEARIllegalCalendarFieldValueException
- if the year is out of rangepublic LocalDate atYear(Year year)
This merges the two objects - this
and the specified year -
to form an instance of LocalDate
.
This instance is immutable and unaffected by this method call.
year
- the year to use, not nullInvalidCalendarFieldException
- if the day does not occur in the yearpublic LocalDate atYear(int year)
This merges the two objects - this
and the specified year -
to form an instance of LocalDate
.
This instance is immutable and unaffected by this method call.
year
- the year to use, from MIN_YEAR to MAX_YEARInvalidCalendarFieldException
- if the day does not occur in the yearpublic int compareTo(DayOfYear otherDayOfYear)
compareTo
in interface java.lang.Comparable<DayOfYear>
otherDayOfYear
- the other day-of-year instance, not nulljava.lang.NullPointerException
- if otherDayOfYear is nullpublic boolean equals(java.lang.Object otherDayOfYear)
equals
in class java.lang.Object
otherDayOfYear
- the other day-of-year instance, null returns falsepublic int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object