2015-W13
YearWeek is an immutable date-time object that represents the combination
of a week-based-year and week-of-week-based-year.
Any field that can be derived from those two fields can be obtained.
This class does not store or represent a day, time or time-zone.
For example, the value "13th week of 2007" can be stored in a YearWeek.
The ISO-8601 calendar system is the modern civil calendar system used today in most of the world. It is equivalent to the proleptic Gregorian calendar system, in which today's rules for leap years are applied for all time. For most applications written today, the ISO-8601 rules are entirely suitable. However, any application that makes use of historical dates, and requires them to be accurate will find the ISO-8601 approach unsuitable.
ISO-8601 defines the week as always starting with Monday. The first week is the week which contains the first Thursday of the calendar year. As such, the week-based-year used in this class does not align with the calendar year.
This class must be treated as a value type. Do not synchronize, rely on the identity hash code or use the distinction between equals() and ==.
| Modifier and Type | Field and Description |
|---|---|
| private static final DateTimeFormatter | PARSER
Parser. |
| private static final long | serialVersionUID
Serialization version. |
| private final int | week
The week-of-week-based-year |
| private final int | year
The week-based-year. |
| Access | Constructor and Description |
|---|---|
| private | YearWeek(int
the week-based-year to represent, validated from MIN_YEAR to MAX_YEAR weekBasedYear, int the week to represent, validated week)Constructor. |
| Modifier and Type | Method and Description |
|---|---|
| public Temporal | Returns: the adjusted object, not nullthe target object to be adjusted, not null temporal)Implements java. Adjusts the specified temporal object to have this year-week. |
| public LocalDate | |
| public int | Returns: the comparator value, negative if less, positive if greaterthe other year-week to compare to, not null other)Implements java. Compares this year-week to another The comparison is based first on the value of the year, then on the value of the week. |
| private long | |
| public boolean | Returns: true if this is equal to the other year-weekthe object to check, null returns false obj)Overrides java. Checks if this year-week is equal to another year-week. |
| public String | Returns: the formatted year-week string, not nullthe formatter to use, not null formatter)Formats this year-week using the specified formatter. |
| public static YearWeek | Returns: the year-week, not nullthe temporal object to convert, not null temporal)Obtains an instance of |
| public int | Returns: the value for the fieldthe field to get, not null field)Overrides default java. Gets the value of the specified field from this year-week as an |
| public long | Returns: the value for the fieldthe field to get, not null field)Implements java. Gets the value of the specified field from this year-week as a |
| public int | |
| public int | |
| public int | Returns: a suitable hash codeOverrides java. A hash code for this year-week. |
| public boolean | Returns: true if the year has 53 weeks, false otherwiseChecks if the week-based-year has 53 weeks. |
| public boolean | |
| public boolean | |
| public boolean | Returns: true if the field is supported on this year-week, false if notthe field to check, null returns false field)Implements java. Checks if the specified field is supported. |
| public boolean | Returns: true if the unit can be added/subtracted, false if notthe unit to check, null returns false unit)Implements java. Checks if the specified unit is supported. |
| public int | Returns: 364 if the year has 52 weeks, 371 if it has 53 weeksReturns the length of the week-based-year. |
| public YearWeek | Returns: aYearWeek based on this year-week with the subtraction made, not nullthe amount to subtract, not null amountToSubtract)Overrides default java. Returns a copy of this year-week with the specified amount subtracted. |
| public YearWeek | Returns: aYearWeek based on this year-week with the specified amount subtracted, not nullthe amount of the unit to subtract from the result, may be negative amountToSubtract, TemporalUnit the unit of the amount to subtract, not null unit)Overrides default java. Returns a copy of this year-week with the specified amount subtracted. |
| public YearWeek | Returns: the year-week with the weeks subtracted, not nullthe weeks to subtract, may be negative weeksToSubtract)Returns a copy of this year-week with the specified number of weeks subtracted. |
| public YearWeek | Returns: the year-week with the years subtracted, not nullthe years to subtract, may be negative yearsToSubtract)Returns a copy of this year-week with the specified number of years subtracted. |
| public static YearWeek | Returns: the current year-week using the system clock and default time-zone, not nullObtains the current year-week from the system clock in the default time-zone. |
| public static YearWeek | |
| public static YearWeek | |
| public static YearWeek | |
| public static YearWeek | Returns: the year-week, not nullthe week-based-year to represent, from MIN_YEAR to MAX_YEAR weekBasedYear, int the week-of-week-based-year to represent, from 1 to 53 week)Obtains an instance of |
| public static YearWeek | Returns: the parsed year-week, not nullthe text to parse such as "2007-W13", not null text)Obtains an instance of |
| public static YearWeek | Returns: the parsed year-week, not nullthe text to parse, not null text, DateTimeFormatter the formatter to use, not null formatter)Obtains an instance of |
| public YearWeek | Returns: aYearWeek based on this year-week with the addition made, not nullthe amount to add, not null amountToAdd)Overrides default java. Returns a copy of this year-week with the specified amount added. |
| public YearWeek | Returns: aYearWeek based on this year-week with the specified amount added, not nullthe amount of the unit to add to the result, may be negative amountToAdd, TemporalUnit the unit of the amount to add, not null unit)Implements java. Returns a copy of this year-week with the specified amount added. |
| public YearWeek | Returns: the year-week with the weeks added, not nullthe weeks to add, may be negative weeksToAdd)Returns a copy of this year-week with the specified number of weeks added. |
| public YearWeek | Returns: the year-week with the years added, not nullthe years to add, may be negative yearsToAdd)Returns a copy of this year-week with the specified number of years added. |
| public < the type of the result R> R | Returns: the query result, null may be returned (defined by the query)the query to invoke, not null query)Overrides default java. Queries this year-week using the specified query. |
| public ValueRange | Returns: the range of valid values for the field, not nullthe field to query the range for, not null field)Overrides default java. Gets the range of valid values for the specified field. |
| private Object | |
| public String | Returns: a string representation of this year-week, not nullOverrides java. Outputs this year-week as a |
| public long | Returns: the amount of time between this year-week and the end year-weekthe end date, exclusive, which is converted to a endExclusive, TemporalUnit YearWeek, not nullthe unit to measure the amount in, not null unit)Implements java. Calculates the amount of time until another year-week in terms of the specified unit. |
| private static int | |
| private YearWeek | Returns: the year-week, not nullthe year to represent, validated from MIN_YEAR to MAX_YEAR newYear, int the week to represent, validated from 1 to 53 newWeek)Returns a copy of this year-week with the new year and week, checking to see if a new object is in fact required. |
| public YearWeek | Returns: aYearWeek based on this with the adjustment made, not nullthe adjuster to use, not null adjuster)Overrides default java. Returns an adjusted copy of this year-week. |
| public YearWeek | Returns: aYearWeek based on this with the specified field set, not nullthe field to set in the result, not null field, long the new value of the field in the result newValue)Implements java. Returns a copy of this year-week with the specified field set to a new value. |
| public YearWeek | Returns: aYearWeek based on this year-week with the requested week, not nullthe week-of-week-based-year to set in the returned year-week week)Returns a copy of this |
| public YearWeek | Returns: aYearWeek based on this year-week with the requested year, not nullthe week-based-year to set in the returned year-week weekBasedYear)Returns a copy of this |
| private long |
| PARSER | back to summary |
|---|---|
| private static final DateTimeFormatter PARSER Parser. | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Serialization version. | |
| week | back to summary |
|---|---|
| private final int week The week-of-week-based-year | |
| year | back to summary |
|---|---|
| private final int year The week-based-year. | |
| YearWeek | back to summary |
|---|---|
| private YearWeek(int weekBasedYear, int week) Constructor.
| |
| adjustInto | back to summary |
|---|---|
| public Temporal adjustInto(Temporal temporal) Implements java. Adjusts the specified temporal object to have this year-week. This returns a temporal object of the same observable type as the input with the week-based-year and week changed to be the same as this.
The adjustment is equivalent to using
In most cases, it is clearer to reverse the calling pattern by using
// these two lines are equivalent, but the second approach is recommended temporal = thisYearWeek.adjustInto(temporal); temporal = temporal.with(thisYearWeek); This instance is immutable and unaffected by this method call.
| |
| atDay | back to summary |
|---|---|
| public LocalDate atDay(DayOfWeek dayOfWeek) Combines this year-week with a day-of-week to create a
This returns a This method can be used as part of a chain to produce a date: LocalDate date = yearWeek.atDay(MONDAY); | |
| compareTo | back to summary |
|---|---|
| public int compareTo(YearWeek other) Implements java. Compares this year-week to another
The comparison is based first on the value of the year, then on the value of the week.
It is "consistent with equals", as defined by | |
| daysUntil | back to summary |
|---|---|
| private long daysUntil(YearWeek end) | |
| equals | back to summary |
|---|---|
| public boolean equals(Object obj) Overrides java. Checks if this year-week is equal to another year-week. | |
| format | back to summary |
|---|---|
| public String format(DateTimeFormatter formatter) Formats this year-week using the specified formatter. This year-week will be passed to the formatter to produce a string.
| |
| from | back to summary |
|---|---|
| public static YearWeek from(TemporalAccessor temporal) Obtains an instance of
This obtains a year-week based on the specified temporal.
A
The conversion extracts the
This method matches the signature of the functional interface
| |
| get | back to summary |
|---|---|
| public int get(TemporalField field) Overrides default java. Gets the value of the specified field from this year-week as an This queries this year-week for the value for the specified field. The returned value will always be within the valid range of values for the field. If it is not possible to return the value, because the field is not supported or for some other reason, an exception is thrown.
The value for the
| |
| getLong | back to summary |
|---|---|
| public long getLong(TemporalField field) Implements java. Gets the value of the specified field from this year-week as a This queries this year-week for the value for the specified field. If it is not possible to return the value, because the field is not supported or for some other reason, an exception is thrown.
The value for the
| |
| getWeek | back to summary |
|---|---|
| public int getWeek() Gets the week-of-week-based-year field.
This method returns the primitive
| |
| getYear | back to summary |
|---|---|
| public int getYear() Gets the week-based-year field.
This method returns the primitive Note that the ISO week-based-year does not align with the standard Gregorian/ISO calendar year.
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. A hash code for this year-week.
| |
| is53WeekYear | back to summary |
|---|---|
| public boolean is53WeekYear() Checks if the week-based-year has 53 weeks. This determines if the year has 53 weeks, returning true. If false, the year has 52 weeks.
| |
| isAfter | back to summary |
|---|---|
| public boolean isAfter(YearWeek other) Is this year-week after the specified year-week.
| |
| isBefore | back to summary |
|---|---|
| public boolean isBefore(YearWeek other) Is this year-week before the specified year-week.
| |
| isSupported | back to summary |
|---|---|
| public boolean isSupported(TemporalField field) Implements java. Checks if the specified field is supported.
This checks if this year-week can be queried for the specified field.
If false, then calling the The supported fields are:
ChronoField instances will return false.
If the field is not a
| |
| isSupported | back to summary |
|---|---|
| public boolean isSupported(TemporalUnit unit) Implements java. Checks if the specified unit is supported.
This checks if the specified unit can be added to, or subtracted from, this date-time.
If false, then calling the The supported units are:
ChronoUnit instances will return false.
If the unit is not a
| |
| lengthOfYear | back to summary |
|---|---|
| public int lengthOfYear() Returns the length of the week-based-year. This returns the length of the year in days, either 364 or 371.
| |
| minus | back to summary |
|---|---|
| public YearWeek minus(TemporalAmount amountToSubtract) Overrides default java. Returns a copy of this year-week with the specified amount subtracted.
This returns a
The calculation is delegated to the amount object by calling
This instance is immutable and unaffected by this method call.
| |
| minus | back to summary |
|---|---|
| public YearWeek minus(long amountToSubtract, TemporalUnit unit) Overrides default java. Returns a copy of this year-week with the specified amount subtracted.
This returns a
This method is equivalent to This instance is immutable and unaffected by this method call.
| |
| minusWeeks | back to summary |
|---|---|
| public YearWeek minusWeeks(long weeksToSubtract) Returns a copy of this year-week with the specified number of weeks subtracted. This instance is immutable and unaffected by this method call.
| |
| minusYears | back to summary |
|---|---|
| public YearWeek minusYears(long yearsToSubtract) Returns a copy of this year-week with the specified number of years subtracted. If the week of this instance is 53 and the new year does not have 53 weeks, the week will be adjusted to be 52. This instance is immutable and unaffected by this method call.
| |
| now | back to summary |
|---|---|
| public static YearWeek now() Obtains the current year-week from the system clock in the default time-zone.
This will query the Using this method will prevent the ability to use an alternate clock for testing because the clock is hard-coded.
| |
| now | back to summary |
|---|---|
| public static YearWeek now(ZoneId zone) Obtains the current year-week from the system clock in the specified time-zone.
This will query the Using this method will prevent the ability to use an alternate clock for testing because the clock is hard-coded. | |
| now | back to summary |
|---|---|
| public static YearWeek now(Clock clock) Obtains the current year-week from the specified clock.
This will query the specified clock to obtain the current year-week.
Using this method allows the use of an alternate clock for testing.
The alternate clock may be introduced using | |
| of | back to summary |
|---|---|
| public static YearWeek of(Year year, int week) Obtains an instance of If the week is 53 and the year does not have 53 weeks, week one of the following year is selected.
Note that this class is based on the week-based-year which aligns to Monday to Sunday weeks,
whereas
| |
| of | back to summary |
|---|---|
| public static YearWeek of(int weekBasedYear, int week) Obtains an instance of If the week is 53 and the year does not have 53 weeks, week one of the following year is selected.
| |
| parse | back to summary |
|---|---|
| public static YearWeek parse(CharSequence text) Obtains an instance of
The string must represent a valid year-week.
Week 53 will be adjusted to week 1 of the following year if necessary.
The format must be
| |
| parse | back to summary |
|---|---|
| public static YearWeek parse(CharSequence text, DateTimeFormatter formatter) Obtains an instance of The text is parsed using the formatter, returning a year-week.
| |
| plus | back to summary |
|---|---|
| public YearWeek plus(TemporalAmount amountToAdd) Overrides default java. Returns a copy of this year-week with the specified amount added.
This returns a
The calculation is delegated to the amount object by calling
This instance is immutable and unaffected by this method call.
| |
| plus | back to summary |
|---|---|
| public YearWeek plus(long amountToAdd, TemporalUnit unit) Implements java. Returns a copy of this year-week with the specified amount added.
This returns a
If the field is a
All
If the field is not a This instance is immutable and unaffected by this method call.
| |
| plusWeeks | back to summary |
|---|---|
| public YearWeek plusWeeks(long weeksToAdd) Returns a copy of this year-week with the specified number of weeks added. This instance is immutable and unaffected by this method call.
| |
| plusYears | back to summary |
|---|---|
| public YearWeek plusYears(long yearsToAdd) Returns a copy of this year-week with the specified number of years added. If the week of this instance is 53 and the new year does not have 53 weeks, the week will be adjusted to be 52. This instance is immutable and unaffected by this method call.
| |
| query | back to summary |
|---|---|
| public <R> R query(TemporalQuery<R> query) Overrides default java. Queries this year-week using the specified query.
This queries this year-week using the specified query strategy object.
The
The result of this method is obtained by invoking the
| |
| range | back to summary |
|---|---|
| public ValueRange range(TemporalField field) Overrides default java. Gets the range of valid values for the specified field. The range object expresses the minimum and maximum valid values for a field. This year-week is used to enhance the accuracy of the returned range. If it is not possible to return the range, because the field is not supported or for some other reason, an exception is thrown.
The range for the
| |
| readResolve | back to summary |
|---|---|
| private Object readResolve() Validates the input.
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Outputs this year-week as a
The output will be in the format | |
| until | back to summary |
|---|---|
| public long until(Temporal endExclusive, TemporalUnit unit) Implements java. Calculates the amount of time until another year-week in terms of the specified unit.
This calculates the amount of time between two The calculation returns a whole number, representing the number of complete units between the two year-weeks. For example, the period in years between 2012-W23 and 2032-W22 will only be 9 years as it is one week short of 10 years.
There are two equivalent ways of using this method.
The first is to invoke this method.
The second is to use // these two lines are equivalent amount = start.until(end, WEEKS); amount = WEEKS.between(start, end);The choice should be made based on which makes the code more readable.
The calculation is implemented in this method for units
If the unit is not a This instance is immutable and unaffected by this method call.
| |
| weekRange | back to summary |
|---|---|
| private static int weekRange(int weekBasedYear) | |
| with | back to summary |
|---|---|
| private YearWeek with(int newYear, int newWeek) Returns a copy of this year-week with the new year and week, checking to see if a new object is in fact required.
| |
| with | back to summary |
|---|---|
| public YearWeek with(TemporalAdjuster adjuster) Overrides default java. Returns an adjusted copy of this year-week.
This returns a
The result of this method is obtained by invoking the
This instance is immutable and unaffected by this method call.
| |
| with | back to summary |
|---|---|
| public YearWeek with(TemporalField field, long newValue) Implements java. Returns a copy of this year-week with the specified field set to a new value.
This returns a
If the field is a
All
If the field is not a This instance is immutable and unaffected by this method call.
| |
| withWeek | back to summary |
|---|---|
| public YearWeek withWeek(int week) Returns a copy of this This returns a year-week with the specified week-of-week-based-year. If the new week is 53 and the year does not have 53 weeks, week one of the following year is selected. This instance is immutable and unaffected by this method call.
| |
| withYear | back to summary |
|---|---|
| public YearWeek withYear(int weekBasedYear) Returns a copy of this This returns a year-week with the specified week-based-year. If the week of this instance is 53 and the new year does not have 53 weeks, the week will be adjusted to be 52. This instance is immutable and unaffected by this method call.
| |
| yearsUntil | back to summary |
|---|---|
| private long yearsUntil(YearWeek end) | |