public final class WeekBasedYear extends java.lang.Object implements Calendrical, java.lang.Comparable<WeekBasedYear>, CalendricalMatcher, java.io.Serializable
WeekBasedYear is an immutable time field that can only store a week-based-year. It is a type-safe way of representing a week-based-year in an application.
A week-based-year is the year that is applicable when using the ISO-8601 week based date calculation. In this system, the week-based-year may begin up to three days early or three days late.
For example, 2007-01-01 is Monday, thus the the week-based-year of 2007 also begins on 2007-01-01. In 2008, the first day of the year is Tuesday, with the Monday being in year 2007. However, the week-based-year for both Monday and Tuesday is 2008.
Date DayOfWeek Week-based year 2007-12-30 Sunday 2007-W52 2007-12-31 Monday 2008-W01 2007-01-01 Tuesday 2008-W01
The ISO-8601 rules state that the first week of the year is the one that contains the first Thursday of the year.
Static factory methods allow you to construct instances. The week-based-year may be queried using getValue().
WeekBasedYear is immutable and thread-safe.
Modifier and Type | Field and Description |
---|---|
static int |
MAX_YEAR
Constant for the maximum week-based-year.
|
static int |
MIN_YEAR
Constant for the minimum week-based-year.
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(WeekBasedYear otherWeekyear)
Compares this week-based-year instance to another.
|
boolean |
equals(java.lang.Object otherWeekyear)
Is this instance equal to that specified, evaluating the week-based-year.
|
<T> T |
get(CalendricalRule<T> rule)
Gets the value of the specified calendrical rule.
|
WeekOfWeekBasedYear |
getLastWeekOfWeekyear()
Gets the last week of the week-based-year.
|
int |
getValue()
Gets the week-based-year value.
|
int |
hashCode()
A hash code for the week-based-year object.
|
boolean |
isAfter(WeekBasedYear otherWeekyear)
Is this week-based-year instance after the specified week-based-year.
|
boolean |
isBefore(WeekBasedYear otherWeekyear)
Is this week-based-year instance before the specified week-based-year.
|
int |
lengthInWeeks()
Gets the length of this week-based-year in weeks.
|
boolean |
matchesCalendrical(Calendrical calendrical)
Checks if the week-based-year extracted from the calendrical matches this.
|
static DateTimeFieldRule<java.lang.Integer> |
rule()
Gets the rule that defines how the week-based-year field operates.
|
java.lang.String |
toString()
A string describing the week-based-year object.
|
static WeekBasedYear |
weekBasedYear(Calendrical calendrical)
Obtains an instance of
WeekBasedYear from a calendrical. |
static WeekBasedYear |
weekBasedYear(int weekyear)
Obtains an instance of
WeekBasedYear from a value. |
public static final int MIN_YEAR
public static final int MAX_YEAR
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 WeekBasedYear weekBasedYear(int weekyear)
WeekBasedYear
from a value.weekyear
- the week-based-year to represent, from MIN_YEAR to MAX_YEARIllegalCalendarFieldValueException
- if the week-based-year is invalidpublic static WeekBasedYear weekBasedYear(Calendrical calendrical)
WeekBasedYear
from a calendrical.
This can be used extract the week-based-year value directly from any implementation
of Calendrical
, including those in other calendar systems.
calendrical
- the calendrical to extract from, not nullUnsupportedRuleException
- if the week-based-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 int lengthInWeeks()
public WeekOfWeekBasedYear getLastWeekOfWeekyear()
public int compareTo(WeekBasedYear otherWeekyear)
compareTo
in interface java.lang.Comparable<WeekBasedYear>
otherWeekyear
- the other week-based-year instance, not nulljava.lang.NullPointerException
- if otherWeekyear is nullpublic boolean isAfter(WeekBasedYear otherWeekyear)
otherWeekyear
- the other week-based-year instance, not nulljava.lang.NullPointerException
- if otherWeekyear is nullpublic boolean isBefore(WeekBasedYear otherWeekyear)
otherWeekyear
- the other week-based-year instance, not nulljava.lang.NullPointerException
- if otherWeekyear is nullpublic boolean equals(java.lang.Object otherWeekyear)
equals
in class java.lang.Object
otherWeekyear
- the other week-based-year instance, null returns falsepublic int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object