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:
Date | Day-of-week | First day: Monday Minimal days: 4 | First day: Monday Minimal days: 5 |
---|---|---|---|
2008-12-31 | Wednesday | Week 5 of December 2008 | Week 5 of December 2008 |
2009-01-01 | Thursday | Week 1 of January 2009 | Week 0 of January 2009 |
2009-01-04 | Sunday | Week 1 of January 2009 | Week 0 of January 2009 |
2009-01-05 | Monday | Week 2 of January 2009 | Week 1 of January 2009 |
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.
Date | Day-of-week | First day: Monday Minimal days: 4 | First day: Monday Minimal days: 5 |
---|---|---|---|
2008-12-31 | Wednesday | Week 1 of 2009 | Week 53 of 2008 |
2009-01-01 | Thursday | Week 1 of 2009 | Week 53 of 2008 |
2009-01-04 | Sunday | Week 1 of 2009 | Week 53 of 2008 |
2009-01-05 | Monday | Week 2 of 2009 | Week 1 of 2009 |
Implementation Specification
This class is immutable and thread-safe.
Modifier and Type | Class and Description |
---|---|
pack-priv static class | WeekFields.
Field type that computes DayOfWeek, WeekOfMonth, and WeekOfYear based on a WeekFields. |
Modifier and Type | Field and Description |
---|---|
private static final ConcurrentMap | 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 | firstDayOfWeek
The first day-of-week. |
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 | minimalDays
The minimal number of days in the first week. |
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. |
Access | Constructor 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. |
Modifier and Type | Method and Description |
---|---|
public TemporalField | Returns: a field providing access to the day-of-week with localized numbering, not nullReturns a field to access the day of week based on this |
public boolean | Returns: true if this is equal to the specified rulesthe other rules to compare to, null returns false object)Overrides java. Checks if this |
public DayOfWeek | |
public int | Returns: the minimal number of days in the first week of a month or year, from 1 to 7Gets the minimal number of days in the first week. |
public int | Returns: a suitable hash codeOverrides java. A hash code for this |
public static WeekFields | |
public static WeekFields | |
private void | |
private Object | Returns: the singleton WeekFields for the firstDayOfWeek and minimalDays.Return the singleton WeekFields associated with the
|
public String | Returns: the string representation, not nullOverrides java. A string representation of this |
public TemporalField | Returns: a field providing access to the week-based-year, not nullReturns a field to access the year of a week-based-year based on this |
public TemporalField | Returns: a field providing access to the week-of-month, not nullReturns a field to access the week of month based on this |
public TemporalField | Returns: a field providing access to the week-of-week-based-year, not nullReturns a field to access the week of a week-based-year based on this |
public TemporalField | Returns: a field providing access to the week-of-year, not nullReturns a field to access the week of year based on this |