Package net.time4j

Enum Class Weekday

All Implemented Interfaces:
Serializable, Comparable<Weekday>, java.lang.constant.Constable, TemporalAccessor, Function<PlainDate,​PlainDate>, Predicate<GregorianDate>, UnaryOperator<PlainDate>, ChronoCondition<GregorianDate>, ChronoOperator<PlainDate>, ThreetenAdapter

Enumeration of weekdays.

Several methods with a Weekmodel-parameter support other week models, too.

Author:
Meno Hochschild
  • Enum Constant Details

    • MONDAY

      public static final Weekday MONDAY
      Monday with the numerical ISO-value 1.
    • TUESDAY

      public static final Weekday TUESDAY
      Tuesday with the numerical ISO-value 2.
    • WEDNESDAY

      public static final Weekday WEDNESDAY
      Wednesday with the numerical ISO-value 3.
    • THURSDAY

      public static final Weekday THURSDAY
      Thursday with the numerical ISO-value 4.
    • FRIDAY

      public static final Weekday FRIDAY
      Friday with the numerical ISO-value 5.
    • SATURDAY

      public static final Weekday SATURDAY
      Saturday with the numerical ISO-value 6.
    • SUNDAY

      public static final Weekday SUNDAY
      Sunday with the numerical ISO-value 7.
  • Method Details

    • values

      public static Weekday[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static Weekday valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • getValue

      public int getValue()

      Gets the corresponding numerical ISO-value.

      Returns:
      monday=1, tuesday=2, wednesday=3, thursday=4, friday=5, saturday=6, sunday=7
      See Also:
      valueOf(int), Weekmodel.ISO
    • getValue

      public int getValue(Weekmodel model)

      Gets the numerical value corresponding to the rule of given week model on which day a week starts.

      In US, the rule is applied that weeks start with Sunday. If so then this method will yield 1 for Weekmodel.of(Locale.US) (instead of the ISO-value 7).

      Parameters:
      model - localized week model
      Returns:
      localized weekday number (1 - 7)
      See Also:
      Weekmodel.getFirstDayOfWeek(), values(Weekmodel), valueOf(int, Weekmodel)
    • values

      public static Weekday[] values(Weekmodel model)

      Yields an array which is sorted corresponding to the rule of given week model on which day a week starts.

      The alternative method generated by compiler without any parameters creates an array sorted according to ISO-8601-standard. This method is an overloaded variation where sorting is adjusted.

      Parameters:
      model - localized week model
      Returns:
      new weekday array
      See Also:
      Weekmodel.getFirstDayOfWeek(), getValue(Weekmodel), valueOf(int, Weekmodel)
    • valueOf

      public static Weekday valueOf(int dayOfWeek)

      Gets the enum-constant which corresponds to the given numerical value.

      Parameters:
      dayOfWeek - (monday=1, tuesday=2, wednesday=3, thursday=4, friday=5, saturday=6, sunday=7)
      Returns:
      weekday as enum
      Throws:
      IllegalArgumentException - if the argument is out of range
      See Also:
      getValue(), Weekmodel.ISO
    • valueOf

      public static Weekday valueOf(int dayOfWeek, Weekmodel model)

      Gets the enum-constant which corresponds to the given localized numerical value taking into account given week model.

      Parameters:
      dayOfWeek - localized weekday number (1 - 7)
      model - localized week model
      Returns:
      weekday as enum
      Throws:
      IllegalArgumentException - if the int-argument is out of range
      See Also:
      Weekmodel.getFirstDayOfWeek(), values(Weekmodel), getValue(Weekmodel)
    • valueOf

      public static Weekday valueOf(int year, Month monthOfYear, int dayOfMonth)

      Gets the weekday corresponding to given gregorian date.

      The proleptic gregorian calendar as defined in ISO-8601 is the calculation basis. That means the current leap year rule is even applied for dates before the introduction of gregorian calendar.

      Parameters:
      year - proleptic iso year
      monthOfYear - gregorian month
      dayOfMonth - day of month (1 - 31)
      Returns:
      weekday
      Throws:
      IllegalArgumentException - if the day is out of range
    • next

      public Weekday next()

      Rolls to the next day of week.

      The result is Monday if this method is applied on Sunday.

      Returns:
      next weekday
    • previous

      public Weekday previous()

      Rolls to the previous day of week.

      The result is Sunday if this method is applied on Monday.

      Returns:
      previous weekday
    • roll

      public Weekday roll(int days)

      Rolls this day of week by given amount of days.

      Parameters:
      days - count of days (maybe negative)
      Returns:
      result of rolling operation
    • getDisplayName

      public String getDisplayName(Locale locale)

      Equivalent to the expression getDisplayName(locale, TextWidth.WIDE, OutputContext.FORMAT).

      Parameters:
      locale - language setting
      Returns:
      descriptive text (long form, never null)
      See Also:
      getDisplayName(Locale, TextWidth, OutputContext)
    • getDisplayName

      public String getDisplayName(Locale locale, TextWidth width, OutputContext context)

      Gets the description text dependent on the locale and style parameters.

      The second argument controls the width of description while the third argument is only relevant for languages which make a difference between stand-alone forms and embedded text forms (does not matter in English).

      Parameters:
      locale - language setting
      width - text width
      context - output context
      Returns:
      descriptive text for given locale and style (never null)
    • parse

      public static Weekday parse(CharSequence text, Locale locale, TextWidth width, OutputContext context) throws ParseException

      Tries to interprete given text as day-of-week.

      Parameters:
      text - the text to be parsed
      locale - language setting
      width - expected text width
      context - expected output context
      Returns:
      the parsed day of week if successful
      Throws:
      ParseException - if parsing fails
      Since:
      3.33/4.28
      See Also:
      getDisplayName(Locale, TextWidth, OutputContext)
    • test

      public boolean test(GregorianDate context)
      Description copied from interface: ChronoCondition

      Decides if given context matches this condition.

      Due to better readability it is recommended to use following equivalent approach instead of this method::

        import static net.time4j.Weekday.SATURDAY;
        import static net.time4j.Month.JANUARY;
      
        PlainDate date = PlainDate.of(2014, JANUARY, 25);
        System.out.println(SATURDAY.test(date)); // direct use
        System.out.println(date.matches(SATURDAY)); // recommended callback
       
      Specified by:
      test in interface ChronoCondition<GregorianDate>
      Specified by:
      test in interface Predicate<GregorianDate>
      Parameters:
      context - context as base of testing this condition
      Returns:
      true if given time context matches this condition else false
    • toTemporalAccessor

      public DayOfWeek toTemporalAccessor()

      Conversion to the java.time-equivalent.

      Specified by:
      toTemporalAccessor in interface ThreetenAdapter
      Returns:
      DayOfWeek
      Since:
      4.28
      See Also:
      from(DayOfWeek)
    • from

      public static Weekday from(DayOfWeek dayOfWeek)

      Conversion from the java.time-equivalent.

      Parameters:
      dayOfWeek - the day of week to be converted
      Returns:
      Weekday
      Since:
      4.28
      See Also:
      toTemporalAccessor()
    • apply

      public PlainDate apply(PlainDate date)
      Description copied from interface: ChronoOperator

      Adjusts given entity and yields a changed copy of argument.

      Will be called by ChronoEntity.with(ChronoOperator).

      Specified by:
      apply in interface ChronoOperator<PlainDate>
      Specified by:
      apply in interface Function<PlainDate,​PlainDate>
      Parameters:
      date - chronological entity to be adjusted
      Returns:
      adjusted copy of argument which itself remains unaffected