Class Weekmodel
- All Implemented Interfaces:
Serializable
Defines rules for the localized handling of weekdays and calendar weeks on the base of a seven-day-week.
- 1st rule: Which day of week is the first day of calendar week?
- 2nd rule: What is the minimum count of days in the first calendar week of the year?
Furthermore, a Weekmodel
contains some week-related elements
which can be used in all types containing an ISO-8601-date
(PlainTimestamp
and PlainDate
).
- Author:
- Meno Hochschild
- See Also:
WeekdataProvider
, Serialized Form
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionDefines an element for the week of month with a localized week number, constrained to the current calendar month.Defines an element for the week of year with a localized week number, constrained to the current calendar year.boolean
Compares on the base of internal week rules.Defines the last day of weekend.Defines the first day of the calendar week in this model.Gets the first working day as first day after end of weekend.int
Defines the minimum count of days the first calendar week of year (or month) must contain.Defines the first day of the weekend.int
hashCode()
Defines the hash value.Defines an element for the weekday with a localized day number in the value range1-7
.static Weekmodel
Gets a suitable weekmodel for the given country.static Weekmodel
Creates a new week model with the given rules and the weekend-definition Saturday/Sunday.static Weekmodel
of(Weekday firstDayOfWeek, int minimalDaysInFirstWeek, Weekday startOfWeekend, Weekday endOfWeekend)
Creates a new week model with the given rules.static Weekmodel
ofSystem()
Gets a suitable weekmodel for the default locale of system.stream()
Obtains a stream where the first element is the first day of week.toString()
Debugging-support.weekend()
Defines a chronological condition if a date matches a weekend.Defines an element for the calendar week of month with a localized week number.Defines an element for the calendar week of year with a localized week number.
-
Field Details
-
ISO
Standard week rules as defined by ISO-8601.
Monday is considered as first day of calendar week. And the first calendar week of year must contain at least four days respective contain the first Thursday of year. Saturday and Sunday are considered as weekend.
-
-
Method Details
-
of
Creates a new week model with the given rules and the weekend-definition Saturday/Sunday.
- Parameters:
firstDayOfWeek
- localized first day of weekminimalDaysInFirstWeek
- required minimum count of days for the first week of year in range (1-7)- Returns:
- specific week model with weekend on saturday and sunday
- Throws:
IllegalArgumentException
- if any argument is out of range- See Also:
of(Locale)
-
of
public static Weekmodel of(Weekday firstDayOfWeek, int minimalDaysInFirstWeek, Weekday startOfWeekend, Weekday endOfWeekend)Creates a new week model with the given rules.
- Parameters:
firstDayOfWeek
- localized first day of weekminimalDaysInFirstWeek
- required minimum count of days for the first week of year in range (1-7)startOfWeekend
- first day of weekendendOfWeekend
- last day of weekend- Returns:
- specific week model
- Throws:
IllegalArgumentException
- if any argument is out of range- See Also:
of(Locale)
-
ofSystem
Gets a suitable weekmodel for the default locale of system.
Note: In order to get a weekend definition deviating from the standard Saturday + Sunday, the i18n-module must be present in classpath since v2.2.
- Returns:
- week model in system locale
- See Also:
Locale.getDefault()
-
of
Gets a suitable weekmodel for the given country.
Note: In order to get a weekend definition deviating from the standard Saturday + Sunday, the i18n-module must be present in classpath since v2.2. If the given locale is the root locale then this method will just return
ISO
.This method is able to handle the unicode extension "fw" which specifies and overrides the first day of week since v4.32 and if the default
WeekdataProvider
has not been changed. Example:Locale locale = Locale.forLanguageTag("en-US-u-fw-mon"); assertThat(Weekmodel.of(locale), is(Weekmodel.of(Weekday.MONDAY, 1)));
- Parameters:
locale
- country setting- Returns:
- localized week model
-
getFirstDayOfWeek
Defines the first day of the calendar week in this model.
The first day of week is not required to be identical with the first working day. It rather marks the the first column a graphical localized calendar. However, in ISO-8601 the first day of week and the first working day (equal to first day after weekend) are identical.
- Returns:
- start of week
- See Also:
getFirstWorkday()
-
getMinimalDaysInFirstWeek
public int getMinimalDaysInFirstWeek()Defines the minimum count of days the first calendar week of year (or month) must contain.
If this method yields
1
then the first calendar week of year always contains the first of January. If the return value is7
instead then only the first full seven-day-week is the first calendar week of year. In ISO-8601 the value is4
.- Returns:
- required count of days for first week of year in the range (1-7)
-
getStartOfWeekend
Defines the first day of the weekend.
In ISO-8601 Saturday is considered as start of weekend (note: not explicitly mentioned in ISO-paper).
- Returns:
- start of weekend
-
getEndOfWeekend
Defines the last day of weekend.
In ISO-8601 Sunday is considered as end of weekend (note: not explicitly mentioned in ISO-paper).
- Returns:
- end of weekend
-
getFirstWorkday
Gets the first working day as first day after end of weekend.
Note: The last working day of week is not well defined however and needs to be defined by the application itself. For example Saturday is considered as start of weekend but also handled as legal working day in most countries.
- Returns:
- first day after weekend
-
weekOfYear
Defines an element for the calendar week of year with a localized week number.
In ISO-8601 the value range is given by
1-52/53
. Reference year is the week-based year, not the calendar year. Therefore the maximum of this element is equivalent to the last calendar week of the week-based year. Examples:PlainDate date1 = PlainDate.of(2012, 12, 31); // Monday System.out.println(date1.get(Weekmodel.ISO.weekOfYear())); // Output: 1 (first calendar week of year 2013) PlainDate date2 = PlainDate.of(2000, 1, 2); // Sunday System.out.println(date2.get(Weekmodel.ISO.weekOfYear())); // Output: 52 (last calendar week of year 1999)
Note: This element uses the lenient mode if new values are to be set (
isLenient() == true
).- Returns:
- localized week of year
-
weekOfMonth
Defines an element for the calendar week of month with a localized week number.
In ISO-8601 the value range is given by
1-4/5
. The behaviour is fully conform to the week of year - like in CLDR standard.Note: This element uses the lenient mode if new values are to be set (
isLenient() == true
).- Returns:
- localized week of month
- See Also:
weekOfYear()
-
localDayOfWeek
Defines an element for the weekday with a localized day number in the value range
1-7
.This element defines localized weekday numbers in numerical formatting and also a localized sorting order of weekdays, but still manages values of type
Weekday
. However, the value range with its minimum and maximum is localized, too, i.e. the element defines as minium the valuegetFirstDayOfWeek()
.In contrast the element
PlainDate.DAY_OF_WEEK
defines a strict ISO-8601-conforming order and ISO-weekday-numbers.- Returns:
- day of week with localized order
-
boundedWeekOfYear
Defines an element for the week of year with a localized week number, constrained to the current calendar year.
In ISO-8601-calendars the value range is
0/1-52/53
, in other weekmodels the maximum value can also be54
. In contrast toweekOfYear()
this week can be shortened (less than seven days) at the start or end of a calendar year. If the week normally belongs to the previous year or to the following year then the bounded week gets the value0
resp. for the end of year the incremented maximum value. This behaviour is a simplifying deviation from CLDR-standard.Note: This element uses the lenient mode if new values are to be set (
isLenient() == true
).- Returns:
- week of year within the limits of calendar year
-
boundedWeekOfMonth
Defines an element for the week of month with a localized week number, constrained to the current calendar month.
In ISO-8601-calendars the value range is
0/1-4/5
, in other weekmodels the maximum value can also be6
. In contrast toweekOfMonth()
this week can be shortened (less than seven days) at the start or end of a calendar month. If the week normally belongs to the previous month or to the following month then the bounded week gets the value0
resp. for the end of month the incremented maximum value. This behaviour is a simplifying deviation from CLDR-standard but is the same as defined in the JDK.Note: This element uses the lenient mode if new values are to be set (
isLenient() == true
).- Returns:
- week of month within the limits of calendar month
- See Also:
boundedWeekOfYear()
-
weekend
Defines a chronological condition if a date matches a weekend.
Example:
PlainDate date = new PlainDate(2013, 3, 31); // Sunday System.out.println(date.matches(Weekmodel.ISO.weekend())); // Output: true Locale yemen = new Locale("ar", "YE"); System.out.println(date.matches(Weekmodel.of(yemen).weekend())); // Output: false (in Yemen the weekend matches Friday and Saturday)
- Returns:
- test for weekend
-
stream
Obtains a stream where the first element is the first day of week.
- Returns:
- Stream
- Since:
- 5.4
- See Also:
getFirstDayOfWeek()
-
equals
Compares on the base of internal week rules.
-
hashCode
public int hashCode()Defines the hash value.
-
toString
Debugging-support.
-