APIdia Launch Partner
Top Description Inners Fields Constructors Methods
java.time.temporal

public final Class WeekFields

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Static Imports
java.time.temporal.ChronoField.DAY_OF_MONTH, .ChronoField.DAY_OF_WEEK, .ChronoField.DAY_OF_YEAR, .ChronoField.MONTH_OF_YEAR, .ChronoField.YEAR, .ChronoUnit.DAYS, .ChronoUnit.FOREVER, .ChronoUnit.MONTHS, .ChronoUnit.WEEKS, .ChronoUnit.YEARS

Localized definitions of the day-of-week, week-of-month and week-of-year fields.

A standard week is seven days long, but cultures have different definitions for some other aspects of a week. This class represents the definition of the week, for the purpose of providing TemporalField instances.

WeekFields provides five fields, dayOfWeek(), weekOfMonth(), weekOfYear(), weekOfWeekBasedYear(), and weekBasedYear() that provide access to the values from any temporal object.

The computations for day-of-week, week-of-month, and week-of-year are based on the proleptic-year, month-of-year, day-of-month, and ISO day-of-week which are based on the epoch-day and the chronology. The values may not be aligned with the year-of-Era depending on the Chronology.

A week is defined by:

Together these two values allow a year or month to be divided into weeks.

Week of Month

One field is used: week-of-month. The calculation ensures that weeks never overlap a month boundary. The month is divided into periods where each period starts on the defined first day-of-week. The earliest period is referred to as week 0 if it has less than the minimal number of days and week 1 if it has at least the minimal number of days.
Examples of WeekFields
DateDay-of-week First day: Monday
Minimal days: 4
First day: Monday
Minimal days: 5
2008-12-31Wednesday Week 5 of December 2008Week 5 of December 2008
2009-01-01Thursday Week 1 of January 2009Week 0 of January 2009
2009-01-04Sunday Week 1 of January 2009Week 0 of January 2009
2009-01-05Monday Week 2 of January 2009Week 1 of January 2009

Week of Year

One field is used: week-of-year. The calculation ensures that weeks never overlap a year boundary. The year is divided into periods where each period starts on the defined first day-of-week. The earliest period is referred to as week 0 if it has less than the minimal number of days and week 1 if it has at least the minimal number of days.

Week Based Year

Two fields are used for week-based-year, one for the week-of-week-based-year and one for week-based-year. In a week-based-year, each week belongs to only a single year. Week 1 of a year is the first week that starts on the first day-of-week and has at least the minimum number of days. The first and last weeks of a year may contain days from the previous calendar year or next calendar year respectively.
Examples of WeekFields for week-based-year
DateDay-of-week First day: Monday
Minimal days: 4
First day: Monday
Minimal days: 5
2008-12-31Wednesday Week 1 of 2009Week 53 of 2008
2009-01-01Thursday Week 1 of 2009Week 53 of 2008
2009-01-04Sunday Week 1 of 2009Week 53 of 2008
2009-01-05Monday Week 2 of 2009Week 1 of 2009

Implementation Specification

This class is immutable and thread-safe.

Since
1.8

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
WeekFields.ComputedDayOfField

Field type that computes DayOfWeek, WeekOfMonth, and WeekOfYear based on a WeekFields.

Field Summary

Modifier and TypeField and Description
private static final ConcurrentMap<String, WeekFields>
CACHE

The cache of rules by firstDayOfWeek plus minimalDays.

private final transient TemporalField
dayOfWeek

The field used to access the computed DayOfWeek.

private final DayOfWeek
public static final WeekFields
ISO

The ISO-8601 definition, where a week starts on Monday and the first week has a minimum of 4 days.

private final int
private static final long
serialVersionUID

Serialization version.

public static final WeekFields
SUNDAY_START

The common definition of a week that starts on Sunday and the first week has a minimum of 1 day.

public static final TemporalUnit
WEEK_BASED_YEARS

The unit that represents week-based-years for the purpose of addition and subtraction.

private final transient TemporalField
weekBasedYear

The field that represents the week-based-year.

private final transient TemporalField
weekOfMonth

The field used to access the computed WeekOfMonth.

private final transient TemporalField
weekOfWeekBasedYear

The field that represents the week-of-week-based-year.

private final transient TemporalField
weekOfYear

The field used to access the computed WeekOfYear.

Constructor Summary

AccessConstructor and Description
private
WeekFields(DayOfWeek
the first day of the week, not null
firstDayOfWeek
,
int
the minimal number of days in the first week, from 1 to 7
minimalDaysInFirstWeek
)

Creates an instance of the definition.

Method Summary

Modifier and TypeMethod and Description
public TemporalField

Returns:

a field providing access to the day-of-week with localized numbering, not null
dayOfWeek
()

Returns a field to access the day of week based on this WeekFields.

public boolean

Returns:

true if this is equal to the specified rules
equals
(Object
the other rules to compare to, null returns false
object
)

Overrides java.lang.Object.equals.

Checks if this WeekFields is equal to the specified object.

public DayOfWeek

Returns:

the first day-of-week, not null
getFirstDayOfWeek
()

Gets the first day-of-week.

public int

Returns:

the minimal number of days in the first week of a month or year, from 1 to 7
getMinimalDaysInFirstWeek
()

Gets the minimal number of days in the first week.

public int

Returns:

a suitable hash code
hashCode
()

Overrides java.lang.Object.hashCode.

A hash code for this WeekFields.

public static WeekFields

Returns:

the week-definition, not null
of
(Locale
the locale to use, not null
locale
)

Obtains an instance of WeekFields appropriate for a locale.

public static WeekFields

Returns:

the week-definition, not null
of
(DayOfWeek
the first day of the week, not null
firstDayOfWeek
,
int
the minimal number of days in the first week, from 1 to 7
minimalDaysInFirstWeek
)

Obtains an instance of WeekFields from the first day-of-week and minimal days.

private void
readObject(ObjectInputStream
the stream to read
s
)

Restore the state of a WeekFields from the stream.

private Object

Returns:

the singleton WeekFields for the firstDayOfWeek and minimalDays.
readResolve
()

Return the singleton WeekFields associated with the firstDayOfWeek and minimalDays.

public String

Returns:

the string representation, not null
toString
()

Overrides java.lang.Object.toString.

A string representation of this WeekFields instance.

public TemporalField

Returns:

a field providing access to the week-based-year, not null
weekBasedYear
()

Returns a field to access the year of a week-based-year based on this WeekFields.

public TemporalField

Returns:

a field providing access to the week-of-month, not null
weekOfMonth
()

Returns a field to access the week of month based on this WeekFields.

public TemporalField

Returns:

a field providing access to the week-of-week-based-year, not null
weekOfWeekBasedYear
()

Returns a field to access the week of a week-based-year based on this WeekFields.

public TemporalField

Returns:

a field providing access to the week-of-year, not null
weekOfYear
()

Returns a field to access the week of year based on this WeekFields.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

CACHEback to summary
private static final ConcurrentMap<String, WeekFields> CACHE

The cache of rules by firstDayOfWeek plus minimalDays. Initialized first to be available for definition of ISO, etc.

dayOfWeekback to summary
private final transient TemporalField dayOfWeek

The field used to access the computed DayOfWeek.

firstDayOfWeekback to summary
private final DayOfWeek firstDayOfWeek
ISOback to summary
public static final WeekFields ISO

The ISO-8601 definition, where a week starts on Monday and the first week has a minimum of 4 days.

The ISO-8601 standard defines a calendar system based on weeks. It uses the week-based-year and week-of-week-based-year concepts to split up the passage of days instead of the standard year/month/day.

Note that the first week may start in the previous calendar year. Note also that the first few days of a calendar year may be in the week-based-year corresponding to the previous calendar year.

minimalDaysback to summary
private final int minimalDays
serialVersionUIDback to summary
private static final long serialVersionUID

Serialization version.

Annotations
@Serial
SUNDAY_STARTback to summary
public static final WeekFields SUNDAY_START

The common definition of a week that starts on Sunday and the first week has a minimum of 1 day.

Defined as starting on Sunday and with a minimum of 1 day in the month. This week definition is in use in the US and other European countries.

WEEK_BASED_YEARSback to summary
public static final TemporalUnit WEEK_BASED_YEARS

The unit that represents week-based-years for the purpose of addition and subtraction.

This allows a number of week-based-years to be added to, or subtracted from, a date. The unit is equal to either 52 or 53 weeks. The estimated duration of a week-based-year is the same as that of a standard ISO year at 365.2425 Days.

The rules for addition add the number of week-based-years to the existing value for the week-based-year field retaining the week-of-week-based-year and day-of-week, unless the week number it too large for the target year. In that case, the week is set to the last week of the year with the same day-of-week.

This unit is an immutable and thread-safe singleton.

weekBasedYearback to summary
private final transient TemporalField weekBasedYear

The field that represents the week-based-year.

This field allows the week-based-year value to be queried and set.

This unit is an immutable and thread-safe singleton.

weekOfMonthback to summary
private final transient TemporalField weekOfMonth

The field used to access the computed WeekOfMonth.

weekOfWeekBasedYearback to summary
private final transient TemporalField weekOfWeekBasedYear

The field that represents the week-of-week-based-year.

This field allows the week of the week-based-year value to be queried and set.

This unit is an immutable and thread-safe singleton.

weekOfYearback to summary
private final transient TemporalField weekOfYear

The field used to access the computed WeekOfYear.

Constructor Detail

WeekFieldsback to summary
private WeekFields(DayOfWeek firstDayOfWeek, int minimalDaysInFirstWeek)

Creates an instance of the definition.

Parameters
firstDayOfWeek:DayOfWeek

the first day of the week, not null

minimalDaysInFirstWeek:int

the minimal number of days in the first week, from 1 to 7

Exceptions
IllegalArgumentException:
if the minimal days value is invalid

Method Detail

dayOfWeekback to summary
public TemporalField dayOfWeek()

Returns a field to access the day of week based on this WeekFields.

This is similar to ChronoField#DAY_OF_WEEK but uses values for the day-of-week based on this WeekFields. The days are numbered from 1 to 7 where the first day-of-week is assigned the value 1.

For example, if the first day-of-week is Sunday, then that will have the value 1, with other days ranging from Monday as 2 to Saturday as 7.

In the resolving phase of parsing, a localized day-of-week will be converted to a standardized ChronoField day-of-week. The day-of-week must be in the valid range 1 to 7. Other fields in this class build dates using the standardized day-of-week.

Returns:TemporalField

a field providing access to the day-of-week with localized numbering, not null

equalsback to summary
public boolean equals(Object object)

Overrides java.lang.Object.equals.

Checks if this WeekFields is equal to the specified object.

The comparison is based on the entire state of the rules, which is the first day-of-week and minimal days.

Parameters
object:Object

the other rules to compare to, null returns false

Returns:boolean

true if this is equal to the specified rules

Annotations
@Override
getFirstDayOfWeekback to summary
public DayOfWeek getFirstDayOfWeek()

Gets the first day-of-week.

The first day-of-week varies by culture. For example, the US uses Sunday, while France and the ISO-8601 standard use Monday. This method returns the first day using the standard DayOfWeek enum.

Returns:DayOfWeek

the first day-of-week, not null

getMinimalDaysInFirstWeekback to summary
public int getMinimalDaysInFirstWeek()

Gets the minimal number of days in the first week.

The number of days considered to define the first week of a month or year varies by culture. For example, the ISO-8601 requires 4 days (more than half a week) to be present before counting the first week.

Returns:int

the minimal number of days in the first week of a month or year, from 1 to 7

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

A hash code for this WeekFields.

Returns:int

a suitable hash code

Annotations
@Override
ofback to summary
public static WeekFields of(Locale locale)

Obtains an instance of WeekFields appropriate for a locale.

This will look up appropriate values from the provider of localization data. If the locale contains "fw" (First day of week) and/or "rg" (Region Override) Unicode extensions, returned instance will reflect the values specified with those extensions. If both "fw" and "rg" are specified, the value from the "fw" extension supersedes the implicit one from the "rg" extension.

For example, users who are interested in using an English locale, but want the first day of the week that corresponds with the ISO-8601 standard can call

Locale enIsoLoc = Locale.forLanguageTag("en-u-fw-mon"); WeekFields.of(enIsoLoc).getFirstDayOfWeek(); // returns MONDAY
Locale enIsoLoc = Locale.forLanguageTag("en-u-fw-mon");
WeekFields.of(enIsoLoc).getFirstDayOfWeek(); // returns MONDAY
Parameters
locale:Locale

the locale to use, not null

Returns:WeekFields

the week-definition, not null

ofback to summary
public static WeekFields of(DayOfWeek firstDayOfWeek, int minimalDaysInFirstWeek)

Obtains an instance of WeekFields from the first day-of-week and minimal days.

The first day-of-week defines the ISO DayOfWeek that is day 1 of the week. The minimal number of days in the first week defines how many days must be present in a month or year, starting from the first day-of-week, before the week is counted as the first week. A value of 1 will count the first day of the month or year as part of the first week, whereas a value of 7 will require the whole seven days to be in the new month or year.

WeekFields instances are singletons; for each unique combination of firstDayOfWeek and minimalDaysInFirstWeek the same instance will be returned.

Parameters
firstDayOfWeek:DayOfWeek

the first day of the week, not null

minimalDaysInFirstWeek:int

the minimal number of days in the first week, from 1 to 7

Returns:WeekFields

the week-definition, not null

Exceptions
IllegalArgumentException:
if the minimal days value is less than one or greater than 7
readObjectback to summary
private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException, InvalidObjectException

Restore the state of a WeekFields from the stream. Check that the values are valid.

Parameters
s:ObjectInputStream

the stream to read

Annotations
@Serial
Exceptions
IOException:
if an I/O error occurs
ClassNotFoundException:
if a class cannot be resolved
InvalidObjectException:
if the serialized object has an invalid value for firstDayOfWeek or minimalDays.
readResolveback to summary
private Object readResolve() throws InvalidObjectException

Return the singleton WeekFields associated with the firstDayOfWeek and minimalDays.

Returns:Object

the singleton WeekFields for the firstDayOfWeek and minimalDays.

Annotations
@Serial
Exceptions
InvalidObjectException:
if the serialized object has invalid values for firstDayOfWeek or minimalDays.
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

A string representation of this WeekFields instance.

Returns:String

the string representation, not null

Annotations
@Override
weekBasedYearback to summary
public TemporalField weekBasedYear()

Returns a field to access the year of a week-based-year based on this WeekFields.

This represents the concept of the year where weeks start on a fixed day-of-week, such as Monday and each week belongs to exactly one year. This field is typically used with WeekFields#dayOfWeek() and WeekFields#weekOfWeekBasedYear().

Week one(1) is the week starting on the WeekFields#getFirstDayOfWeek where there are at least WeekFields#getMinimalDaysInFirstWeek() days in the year. Thus, week one may start before the start of the year. If the first week starts after the start of the year then the period before is in the last week of the previous year.

This field can be used with any calendar system.

In the resolving phase of parsing, a date can be created from a week-based-year, week-of-year and day-of-week.

In strict mode, all three fields are validated against their range of valid values. The week-of-year field is validated to ensure that the resulting week-based-year is the week-based-year requested.

In smart mode, all three fields are validated against their range of valid values. The week-of-week-based-year field is validated from 1 to 53, meaning that the resulting date can be in the following week-based-year to that specified.

In lenient mode, the year and day-of-week are validated against the range of valid values. The resulting date is calculated equivalent to the following three stage approach. First, create a date on the first day of the first week in the requested week-based-year. Then take the week-of-week-based-year, subtract one, and add the amount in weeks to the date. Finally, adjust to the correct day-of-week within the localized week.

Returns:TemporalField

a field providing access to the week-based-year, not null

weekOfMonthback to summary
public TemporalField weekOfMonth()

Returns a field to access the week of month based on this WeekFields.

This represents the concept of the count of weeks within the month where weeks start on a fixed day-of-week, such as Monday. This field is typically used with WeekFields#dayOfWeek().

Week one (1) is the week starting on the WeekFields#getFirstDayOfWeek where there are at least WeekFields#getMinimalDaysInFirstWeek() days in the month. Thus, week one may start up to minDays days before the start of the month. If the first week starts after the start of the month then the period before is week zero (0).

For example:
- if the 1st day of the month is a Monday, week one starts on the 1st and there is no week zero
- if the 2nd day of the month is a Monday, week one starts on the 2nd and the 1st is in week zero
- if the 4th day of the month is a Monday, week one starts on the 4th and the 1st to 3rd is in week zero
- if the 5th day of the month is a Monday, week two starts on the 5th and the 1st to 4th is in week one

This field can be used with any calendar system.

In the resolving phase of parsing, a date can be created from a year, week-of-month, month-of-year and day-of-week.

In strict mode, all four fields are validated against their range of valid values. The week-of-month field is validated to ensure that the resulting month is the month requested.

In smart mode, all four fields are validated against their range of valid values. The week-of-month field is validated from 0 to 6, meaning that the resulting date can be in a different month to that specified.

In lenient mode, the year and day-of-week are validated against the range of valid values. The resulting date is calculated equivalent to the following four stage approach. First, create a date on the first day of the first week of January in the requested year. Then take the month-of-year, subtract one, and add the amount in months to the date. Then take the week-of-month, subtract one, and add the amount in weeks to the date. Finally, adjust to the correct day-of-week within the localized week.

Returns:TemporalField

a field providing access to the week-of-month, not null

weekOfWeekBasedYearback to summary
public TemporalField weekOfWeekBasedYear()

Returns a field to access the week of a week-based-year based on this WeekFields.

This represents the concept of the count of weeks within the year where weeks start on a fixed day-of-week, such as Monday and each week belongs to exactly one year. This field is typically used with WeekFields#dayOfWeek() and WeekFields#weekBasedYear().

Week one(1) is the week starting on the WeekFields#getFirstDayOfWeek where there are at least WeekFields#getMinimalDaysInFirstWeek() days in the year. If the first week starts after the start of the year then the period before is in the last week of the previous year.

For example:
- if the 1st day of the year is a Monday, week one starts on the 1st
- if the 2nd day of the year is a Monday, week one starts on the 2nd and the 1st is in the last week of the previous year
- if the 4th day of the year is a Monday, week one starts on the 4th and the 1st to 3rd is in the last week of the previous year
- if the 5th day of the year is a Monday, week two starts on the 5th and the 1st to 4th is in week one

This field can be used with any calendar system.

In the resolving phase of parsing, a date can be created from a week-based-year, week-of-year and day-of-week.

In strict mode, all three fields are validated against their range of valid values. The week-of-year field is validated to ensure that the resulting week-based-year is the week-based-year requested.

In smart mode, all three fields are validated against their range of valid values. The week-of-week-based-year field is validated from 1 to 53, meaning that the resulting date can be in the following week-based-year to that specified.

In lenient mode, the year and day-of-week are validated against the range of valid values. The resulting date is calculated equivalent to the following three stage approach. First, create a date on the first day of the first week in the requested week-based-year. Then take the week-of-week-based-year, subtract one, and add the amount in weeks to the date. Finally, adjust to the correct day-of-week within the localized week.

Returns:TemporalField

a field providing access to the week-of-week-based-year, not null

weekOfYearback to summary
public TemporalField weekOfYear()

Returns a field to access the week of year based on this WeekFields.

This represents the concept of the count of weeks within the year where weeks start on a fixed day-of-week, such as Monday. This field is typically used with WeekFields#dayOfWeek().

Week one(1) is the week starting on the WeekFields#getFirstDayOfWeek where there are at least WeekFields#getMinimalDaysInFirstWeek() days in the year. Thus, week one may start up to minDays days before the start of the year. If the first week starts after the start of the year then the period before is week zero (0).

For example:
- if the 1st day of the year is a Monday, week one starts on the 1st and there is no week zero
- if the 2nd day of the year is a Monday, week one starts on the 2nd and the 1st is in week zero
- if the 4th day of the year is a Monday, week one starts on the 4th and the 1st to 3rd is in week zero
- if the 5th day of the year is a Monday, week two starts on the 5th and the 1st to 4th is in week one

This field can be used with any calendar system.

In the resolving phase of parsing, a date can be created from a year, week-of-year and day-of-week.

In strict mode, all three fields are validated against their range of valid values. The week-of-year field is validated to ensure that the resulting year is the year requested.

In smart mode, all three fields are validated against their range of valid values. The week-of-year field is validated from 0 to 54, meaning that the resulting date can be in a different year to that specified.

In lenient mode, the year and day-of-week are validated against the range of valid values. The resulting date is calculated equivalent to the following three stage approach. First, create a date on the first day of the first week in the requested year. Then take the week-of-year, subtract one, and add the amount in weeks to the date. Finally, adjust to the correct day-of-week within the localized week.

Returns:TemporalField

a field providing access to the week-of-year, not null

java.time.temporal back to summary

pack-priv Class WeekFields.ComputedDayOfField

extends Object
implements TemporalField
Class Inheritance
All Implemented Interfaces
java.time.temporal.TemporalField

Field type that computes DayOfWeek, WeekOfMonth, and WeekOfYear based on a WeekFields. A separate Field instance is required for each different WeekFields; combination of start of week and minimum number of days. Constructors are provided to create fields for DayOfWeek, WeekOfMonth, and WeekOfYear.

Field Summary

Modifier and TypeField and Description
private final TemporalUnit
private static final ValueRange
private final String
private final ValueRange
private final TemporalUnit
private static final ValueRange
private static final ValueRange
private static final ValueRange
private final WeekFields

Constructor Summary

AccessConstructor and Description
private
ComputedDayOfField(String name, WeekFields weekDef, TemporalUnit baseUnit, TemporalUnit rangeUnit, ValueRange range)

Method Summary

Modifier and TypeMethod and Description
public <R extends Temporal> R
adjustInto(R temporal, long newValue)

Implements java.time.temporal.TemporalField.adjustInto.

Returns a copy of the specified temporal object with the value of this field set.

private int

Returns:

the week number where zero is used for a partial week and 1 for the first full week
computeWeek
(int
the offset to align a date with the start of week from startOfWeekOffset.
offset
,
int
the day for which to compute the week number
day
)

Returns the week number computed from the reference day and reference dayOfWeek.

public TemporalUnit
getBaseUnit()

Implements java.time.temporal.TemporalField.getBaseUnit.

Gets the unit that the field is measured in.

The unit of the field is the period that varies within the range.

public String
getDisplayName(Locale locale)

Overrides default java.time.temporal.TemporalField.getDisplayName.

Gets the display name for the field in the requested locale.

public long
getFrom(TemporalAccessor temporal)

Implements java.time.temporal.TemporalField.getFrom.

Gets the value of this field from the specified temporal object.

public TemporalUnit
getRangeUnit()

Implements java.time.temporal.TemporalField.getRangeUnit.

Gets the range that the field is bound by.

public boolean
isDateBased()

Implements java.time.temporal.TemporalField.isDateBased.

Checks if this field represents a component of a date.

public boolean
isSupportedBy(TemporalAccessor temporal)

Implements java.time.temporal.TemporalField.isSupportedBy.

Checks if this field is supported by the temporal object.

public boolean
isTimeBased()

Implements java.time.temporal.TemporalField.isTimeBased.

Checks if this field represents a component of a time.

private int
private int
localizedDayOfWeek(int isoDow)

private int

Returns:

the year of week-based-year for the date
localizedWeekBasedYear
(TemporalAccessor
a date of any chronology, not null
temporal
)

Returns the year of week-based-year for the temporal.

private long
private int

Returns:

the week of the year
localizedWeekOfWeekBasedYear
(TemporalAccessor
a date of any chronology
temporal
)

Returns the week of week-based-year for the temporal.

private long
pack-priv static WeekFields.ComputedDayOfField
ofDayOfWeekField(WeekFields weekDef)

Returns a field to access the day of week, computed based on a WeekFields.

private ChronoLocalDate

Returns:

a ChronoLocalDate for the requested year, week of year, and day of week
ofWeekBasedYear
(Chronology
The chronology of the new date
chrono
,
int
the year of the week-based-year
yowby
,
int
the week of the week-based-year
wowby
,
int
the day of the week
dow
)

Return a new week-based-year date of the Chronology, year, week-of-year, and dow of week.

pack-priv static WeekFields.ComputedDayOfField
ofWeekBasedYearField(WeekFields weekDef)

Returns a field to access the week of week-based-year, computed based on a WeekFields.

pack-priv static WeekFields.ComputedDayOfField
ofWeekOfMonthField(WeekFields weekDef)

Returns a field to access the week of month, computed based on a WeekFields.

pack-priv static WeekFields.ComputedDayOfField
ofWeekOfWeekBasedYearField(WeekFields weekDef)

Returns a field to access the week of week-based-year, computed based on a WeekFields.

pack-priv static WeekFields.ComputedDayOfField
ofWeekOfYearField(WeekFields weekDef)

Returns a field to access the week of year, computed based on a WeekFields.

public ValueRange
range()

Implements java.time.temporal.TemporalField.range.

Gets the range of valid values for the field.

private ValueRange

Returns:

the ValueRange with the range adjusted to weeks.
rangeByWeek
(TemporalAccessor
the temporal
temporal
,
TemporalField
the field to get the range of
field
)

Map the field range to a week range

public ValueRange
rangeRefinedBy(TemporalAccessor temporal)

Implements java.time.temporal.TemporalField.rangeRefinedBy.

Get the range of valid values for this field using the temporal object to refine the result.

private ValueRange

Returns:

the ValueRange with the range adjusted to weeks.
rangeWeekOfWeekBasedYear
(TemporalAccessor
the temporal
temporal
)

Map the field range to a week range of a week year.

public ChronoLocalDate
resolve(Map<TemporalField, Long> fieldValues, TemporalAccessor partialTemporal, ResolverStyle resolverStyle)

Overrides default java.time.temporal.TemporalField.resolve.

Resolves this field to provide a simpler alternative or a date.

private ChronoLocalDate
resolveWBY(Map<TemporalField, Long> fieldValues, Chronology chrono, int localDow, ResolverStyle resolverStyle)

private ChronoLocalDate
resolveWoM(Map<TemporalField, Long> fieldValues, Chronology chrono, int year, long month, long wom, int localDow, ResolverStyle resolverStyle)

private ChronoLocalDate
resolveWoY(Map<TemporalField, Long> fieldValues, Chronology chrono, int year, long woy, int localDow, ResolverStyle resolverStyle)

private int

Returns:

an offset in days to align a day with the start of the first 'full' week
startOfWeekOffset
(int
the day; 1 through infinity
day
,
int
the day of the week of that day; 1 through 7
dow
)

Returns an offset to align week start with a day of month or day of year.

public String
toString()

Overrides java.lang.Object.toString.

Implements java.time.temporal.TemporalField.toString.

Gets a descriptive name for the field.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

baseUnitback to summary
private final TemporalUnit baseUnit
DAY_OF_WEEK_RANGEback to summary
private static final ValueRange DAY_OF_WEEK_RANGE
nameback to summary
private final String name
rangeback to summary
private final ValueRange range
rangeUnitback to summary
private final TemporalUnit rangeUnit
WEEK_OF_MONTH_RANGEback to summary
private static final ValueRange WEEK_OF_MONTH_RANGE
WEEK_OF_WEEK_BASED_YEAR_RANGEback to summary
private static final ValueRange WEEK_OF_WEEK_BASED_YEAR_RANGE
WEEK_OF_YEAR_RANGEback to summary
private static final ValueRange WEEK_OF_YEAR_RANGE
weekDefback to summary
private final WeekFields weekDef

Constructor Detail

ComputedDayOfFieldback to summary
private ComputedDayOfField(String name, WeekFields weekDef, TemporalUnit baseUnit, TemporalUnit rangeUnit, ValueRange range)

Method Detail

adjustIntoback to summary
public <R extends Temporal> R adjustInto(R temporal, long newValue)

Implements java.time.temporal.TemporalField.adjustInto.

Doc from java.time.temporal.TemporalField.adjustInto.

Returns a copy of the specified temporal object with the value of this field set.

This returns a new temporal object based on the specified one with the value for this field changed. For example, on a LocalDate, this could be used to set the year, month or day-of-month. The returned object has the same observable type as the specified object.

In some cases, changing a field is not fully defined. For example, if the target object is a date representing the 31st January, then changing the month to February would be unclear. In cases like this, the implementation is responsible for resolving the result. Typically it will choose the previous valid date, which would be the last valid day of February in this example.

There are two equivalent ways of using this method. The first is to invoke this method directly. The second is to use Temporal#with(TemporalField, long):

  // these two lines are equivalent, but the second approach is recommended
  temporal = thisField.adjustInto(temporal, newValue);
  temporal = temporal.with(thisField, newValue);
It is recommended to use the second approach, with(thisField, newValue), as it is a lot clearer to read in code.

Implementations should perform any queries or calculations using the fields available in ChronoField. If the field is not supported an UnsupportedTemporalTypeException must be thrown.

Implementations must not alter the specified temporal object. Instead, an adjusted copy of the original must be returned. This provides equivalent, safe behavior for immutable and mutable implementations.

Annotations
@SuppressWarnings:unchecked
@Override
computeWeekback to summary
private int computeWeek(int offset, int day)

Returns the week number computed from the reference day and reference dayOfWeek.

Parameters
offset:int

the offset to align a date with the start of week from startOfWeekOffset.

day:int

the day for which to compute the week number

Returns:int

the week number where zero is used for a partial week and 1 for the first full week

getBaseUnitback to summary
public TemporalUnit getBaseUnit()

Implements java.time.temporal.TemporalField.getBaseUnit.

Doc from java.time.temporal.TemporalField.getBaseUnit.

Gets the unit that the field is measured in.

The unit of the field is the period that varies within the range. For example, in the field 'MonthOfYear', the unit is 'Months'. See also getRangeUnit().

Annotations
@Override
getDisplayNameback to summary
public String getDisplayName(Locale locale)

Overrides default java.time.temporal.TemporalField.getDisplayName.

Doc from java.time.temporal.TemporalField.getDisplayName.

Gets the display name for the field in the requested locale.

If there is no display name for the locale then a suitable default must be returned.

The default implementation must check the locale is not null and return toString().

Annotations
@Override
getFromback to summary
public long getFrom(TemporalAccessor temporal)

Implements java.time.temporal.TemporalField.getFrom.

Doc from java.time.temporal.TemporalField.getFrom.

Gets the value of this field from the specified temporal object.

This queries the temporal object for the value of this field.

There are two equivalent ways of using this method. The first is to invoke this method directly. The second is to use TemporalAccessor#getLong(TemporalField) (or TemporalAccessor#get(TemporalField)):

  // these two lines are equivalent, but the second approach is recommended
  value = thisField.getFrom(temporal);
  value = temporal.getLong(thisField);
It is recommended to use the second approach, getLong(thisField), as it is a lot clearer to read in code.

Implementations should perform any queries or calculations using the fields available in ChronoField. If the field is not supported an UnsupportedTemporalTypeException must be thrown.

Annotations
@Override
getRangeUnitback to summary
public TemporalUnit getRangeUnit()

Implements java.time.temporal.TemporalField.getRangeUnit.

Doc from java.time.temporal.TemporalField.getRangeUnit.

Gets the range that the field is bound by.

The range of the field is the period that the field varies within. For example, in the field 'MonthOfYear', the range is 'Years'. See also getBaseUnit().

The range is never null. For example, the 'Year' field is shorthand for 'YearOfForever'. It therefore has a unit of 'Years' and a range of 'Forever'.

Annotations
@Override
isDateBasedback to summary
public boolean isDateBased()

Implements java.time.temporal.TemporalField.isDateBased.

Doc from java.time.temporal.TemporalField.isDateBased.

Checks if this field represents a component of a date.

A field is date-based if it can be derived from EPOCH_DAY. Note that it is valid for both isDateBased() and isTimeBased() to return false, such as when representing a field like minute-of-week.

Annotations
@Override
isSupportedByback to summary
public boolean isSupportedBy(TemporalAccessor temporal)

Implements java.time.temporal.TemporalField.isSupportedBy.

Doc from java.time.temporal.TemporalField.isSupportedBy.

Checks if this field is supported by the temporal object.

This determines whether the temporal accessor supports this field. If this returns false, then the temporal cannot be queried for this field.

There are two equivalent ways of using this method. The first is to invoke this method directly. The second is to use TemporalAccessor#isSupported(TemporalField):

  // these two lines are equivalent, but the second approach is recommended
  supported = thisField.isSupportedBy(temporal);
  supported = temporal.isSupported(thisField);
It is recommended to use the second approach, isSupported(thisField), as it is a lot clearer to read in code.

Implementations should determine whether they are supported using the fields available in ChronoField.

Annotations
@Override
isTimeBasedback to summary
public boolean isTimeBased()

Implements java.time.temporal.TemporalField.isTimeBased.

Doc from java.time.temporal.TemporalField.isTimeBased.

Checks if this field represents a component of a time.

A field is time-based if it can be derived from NANO_OF_DAY. Note that it is valid for both isDateBased() and isTimeBased() to return false, such as when representing a field like minute-of-week.

Annotations
@Override
localizedDayOfWeekback to summary
private int localizedDayOfWeek(TemporalAccessor temporal)
localizedDayOfWeekback to summary
private int localizedDayOfWeek(int isoDow)
localizedWeekBasedYearback to summary
private int localizedWeekBasedYear(TemporalAccessor temporal)

Returns the year of week-based-year for the temporal. The year can be the previous year, the current year, or the next year.

Parameters
temporal:TemporalAccessor

a date of any chronology, not null

Returns:int

the year of week-based-year for the date

localizedWeekOfMonthback to summary
private long localizedWeekOfMonth(TemporalAccessor temporal)
localizedWeekOfWeekBasedYearback to summary
private int localizedWeekOfWeekBasedYear(TemporalAccessor temporal)

Returns the week of week-based-year for the temporal. The week can be part of the previous year, the current year, or the next year depending on the week start and minimum number of days.

Parameters
temporal:TemporalAccessor

a date of any chronology

Returns:int

the week of the year

See Also
localizedWeekBasedYear(java.time.temporal.TemporalAccessor)
localizedWeekOfYearback to summary
private long localizedWeekOfYear(TemporalAccessor temporal)
ofDayOfWeekFieldback to summary
pack-priv static WeekFields.ComputedDayOfField ofDayOfWeekField(WeekFields weekDef)

Returns a field to access the day of week, computed based on a WeekFields.

The WeekDefintion of the first day of the week is used with the ISO DAY_OF_WEEK field to compute week boundaries.

ofWeekBasedYearback to summary
private ChronoLocalDate ofWeekBasedYear(Chronology chrono, int yowby, int wowby, int dow)

Return a new week-based-year date of the Chronology, year, week-of-year, and dow of week.

Parameters
chrono:Chronology

The chronology of the new date

yowby:int

the year of the week-based-year

wowby:int

the week of the week-based-year

dow:int

the day of the week

Returns:ChronoLocalDate

a ChronoLocalDate for the requested year, week of year, and day of week

ofWeekBasedYearFieldback to summary
pack-priv static WeekFields.ComputedDayOfField ofWeekBasedYearField(WeekFields weekDef)

Returns a field to access the week of week-based-year, computed based on a WeekFields.

See Also
WeekFields#weekBasedYear()
ofWeekOfMonthFieldback to summary
pack-priv static WeekFields.ComputedDayOfField ofWeekOfMonthField(WeekFields weekDef)

Returns a field to access the week of month, computed based on a WeekFields.

See Also
WeekFields#weekOfMonth()
ofWeekOfWeekBasedYearFieldback to summary
pack-priv static WeekFields.ComputedDayOfField ofWeekOfWeekBasedYearField(WeekFields weekDef)

Returns a field to access the week of week-based-year, computed based on a WeekFields.

See Also
WeekFields#weekOfWeekBasedYear()
ofWeekOfYearFieldback to summary
pack-priv static WeekFields.ComputedDayOfField ofWeekOfYearField(WeekFields weekDef)

Returns a field to access the week of year, computed based on a WeekFields.

See Also
WeekFields#weekOfYear()
rangeback to summary
public ValueRange range()

Implements java.time.temporal.TemporalField.range.

Doc from java.time.temporal.TemporalField.range.

Gets the range of valid values for the field.

All fields can be expressed as a long integer. This method returns an object that describes the valid range for that value. This method is generally only applicable to the ISO-8601 calendar system.

Note that the result only describes the minimum and maximum valid values and it is important not to read too much into them. For example, there could be values within the range that are invalid for the field.

Annotations
@Override
rangeByWeekback to summary
private ValueRange rangeByWeek(TemporalAccessor temporal, TemporalField field)

Map the field range to a week range

Parameters
temporal:TemporalAccessor

the temporal

field:TemporalField

the field to get the range of

Returns:ValueRange

the ValueRange with the range adjusted to weeks.

rangeRefinedByback to summary
public ValueRange rangeRefinedBy(TemporalAccessor temporal)

Implements java.time.temporal.TemporalField.rangeRefinedBy.

Doc from java.time.temporal.TemporalField.rangeRefinedBy.

Get the range of valid values for this field using the temporal object to refine the result.

This uses the temporal object to find the range of valid values for the field. This is similar to range(), however this method refines the result using the temporal. For example, if the field is DAY_OF_MONTH the range method is not accurate as there are four possible month lengths, 28, 29, 30 and 31 days. Using this method with a date allows the range to be accurate, returning just one of those four options.

There are two equivalent ways of using this method. The first is to invoke this method directly. The second is to use TemporalAccessor#range(TemporalField):

  // these two lines are equivalent, but the second approach is recommended
  range = thisField.rangeRefinedBy(temporal);
  range = temporal.range(thisField);
It is recommended to use the second approach, range(thisField), as it is a lot clearer to read in code.

Implementations should perform any queries or calculations using the fields available in ChronoField. If the field is not supported an UnsupportedTemporalTypeException must be thrown.

Annotations
@Override
rangeWeekOfWeekBasedYearback to summary
private ValueRange rangeWeekOfWeekBasedYear(TemporalAccessor temporal)

Map the field range to a week range of a week year.

Parameters
temporal:TemporalAccessor

the temporal

Returns:ValueRange

the ValueRange with the range adjusted to weeks.

resolveback to summary
public ChronoLocalDate resolve(Map<TemporalField, Long> fieldValues, TemporalAccessor partialTemporal, ResolverStyle resolverStyle)

Overrides default java.time.temporal.TemporalField.resolve.

Doc from java.time.temporal.TemporalField.resolve.

Resolves this field to provide a simpler alternative or a date.

This method is invoked during the resolve phase of parsing. It is designed to allow application defined fields to be simplified into more standard fields, such as those on ChronoField, or into a date.

Applications should not normally invoke this method directly.

Annotations
@Override
resolveWBYback to summary
private ChronoLocalDate resolveWBY(Map<TemporalField, Long> fieldValues, Chronology chrono, int localDow, ResolverStyle resolverStyle)
resolveWoMback to summary
private ChronoLocalDate resolveWoM(Map<TemporalField, Long> fieldValues, Chronology chrono, int year, long month, long wom, int localDow, ResolverStyle resolverStyle)
resolveWoYback to summary
private ChronoLocalDate resolveWoY(Map<TemporalField, Long> fieldValues, Chronology chrono, int year, long woy, int localDow, ResolverStyle resolverStyle)
startOfWeekOffsetback to summary
private int startOfWeekOffset(int day, int dow)

Returns an offset to align week start with a day of month or day of year.

Parameters
day:int

the day; 1 through infinity

dow:int

the day of the week of that day; 1 through 7

Returns:int

an offset in days to align a day with the start of the first 'full' week

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Implements java.time.temporal.TemporalField.toString.

Doc from java.time.temporal.TemporalField.toString.

Gets a descriptive name for the field.

The should be of the format 'BaseOfRange', such as 'MonthOfYear', unless the field has a range of FOREVER, when only the base unit is mentioned, such as 'Year' or 'Era'.

Annotations
@Override