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
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.

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