Package net.time4j

Class Weekmodel

java.lang.Object
net.time4j.Weekmodel
All Implemented Interfaces:
Serializable

public final class Weekmodel extends Object implements 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 Details

    • ISO

      public static final Weekmodel 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

      public static Weekmodel of(Weekday firstDayOfWeek, int minimalDaysInFirstWeek)

      Creates a new week model with the given rules and the weekend-definition Saturday/Sunday.

      Parameters:
      firstDayOfWeek - localized first day of week
      minimalDaysInFirstWeek - 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 week
      minimalDaysInFirstWeek - required minimum count of days for the first week of year in range (1-7)
      startOfWeekend - first day of weekend
      endOfWeekend - last day of weekend
      Returns:
      specific week model
      Throws:
      IllegalArgumentException - if any argument is out of range
      See Also:
      of(Locale)
    • ofSystem

      public static Weekmodel 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

      public static Weekmodel of(Locale locale)

      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

      public Weekday 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 is 7 instead then only the first full seven-day-week is the first calendar week of year. In ISO-8601 the value is 4.

      Returns:
      required count of days for first week of year in the range (1-7)
    • getStartOfWeekend

      public Weekday 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

      public Weekday 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

      public Weekday 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

      @FormattableElement(format="e", alt="c") public NavigableElement<Weekday> 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 value getFirstDayOfWeek().

      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

      public AdjustableElement<Integer,​PlainDate> 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 be 54. In contrast to weekOfYear() 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 value 0 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

      public AdjustableElement<Integer,​PlainDate> 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 be 6. In contrast to weekOfMonth() 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 value 0 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

      public ChronoCondition<GregorianDate> 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

      public Stream<Weekday> stream()

      Obtains a stream where the first element is the first day of week.

      Returns:
      Stream
      Since:
      5.4
      See Also:
      getFirstDayOfWeek()
    • equals

      public boolean equals(Object obj)

      Compares on the base of internal week rules.

      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()

      Defines the hash value.

      Overrides:
      hashCode in class Object
    • toString

      public String toString()

      Debugging-support.

      Overrides:
      toString in class Object