Enum DayOfWeek
- java.lang.Object
-
- java.lang.Enum<DayOfWeek>
-
- javax.time.calendar.DayOfWeek
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Comparable<DayOfWeek>
,Calendrical
public enum DayOfWeek extends java.lang.Enum<DayOfWeek> implements Calendrical
A day-of-week, such as 'Tuesday'.DayOfWeek
is an enum representing the 7 days of the week - Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday.The calendrical framework requires date-time fields to have an
int
value. Theint
value follows the ISO-8601 standard, from 1 (Monday) to 7 (Sunday). It is recommended that applications use the enum rather than theint
value to ensure code clarity.Do not use
ordinal()
to obtain the numeric representation ofDayOfWeek
. UsegetValue()
instead.This enum represents a common concept that is found in many calendar systems. As such, this enum may be used by any calendar system that has the day-of-week concept with a seven day week where the names are equivalent to those defined. Note that the implementation of
DateTimeFieldRule
for day-of-week may vary by calendar system.DayOfWeek is an immutable and thread-safe enum.
-
-
Enum Constant Summary
Enum Constants Enum Constant Description FRIDAY
The singleton instance for the day-of-week of Friday.MONDAY
The singleton instance for the day-of-week of Monday.SATURDAY
The singleton instance for the day-of-week of Saturday.SUNDAY
The singleton instance for the day-of-week of Sunday.THURSDAY
The singleton instance for the day-of-week of Thursday.TUESDAY
The singleton instance for the day-of-week of Tuesday.WEDNESDAY
The singleton instance for the day-of-week of Wednesday.
-
Constructor Summary
Constructors Modifier Constructor Description private
DayOfWeek()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static DayOfWeek
firstDayOfWeekFor(java.util.Locale locale)
Returns theDayOfWeek
instance that corresponds to the first day-of-week for a givenlocale
.<T> T
get(CalendricalRule<T> rule)
Gets the value of the specified calendrical rule.java.lang.String
getShortText(java.util.Locale locale)
Gets the short textual representation of this day-of-week, such as 'Mon' or 'Fri'.java.lang.String
getText(java.util.Locale locale)
Gets the full textual representation of this day-of-week, such as 'Monday' or 'Friday'.int
getValue()
Gets the day-of-weekint
value.boolean
isFriday()
Is this instance representing Friday.boolean
isMonday()
Is this instance representing Monday.boolean
isSaturday()
Is this instance representing Saturday.boolean
isSunday()
Is this instance representing Sunday.boolean
isThursday()
Is this instance representing Thursday.boolean
isTuesday()
Is this instance representing Tuesday.boolean
isWednesday()
Is this instance representing Wednesday.DayOfWeek
next()
Gets the next day-of-week.static DayOfWeek
of(int dayOfWeek)
Obtains an instance ofDayOfWeek
from anint
value.DayOfWeek
previous()
Gets the previous day-of-week.DayOfWeek
roll(int days)
Rolls the day-of-week, adding the specified number of days.static DayOfWeek
valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name.static DayOfWeek[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.
-
-
-
Enum Constant Detail
-
MONDAY
public static final DayOfWeek MONDAY
The singleton instance for the day-of-week of Monday. This has the numeric value of1
.
-
TUESDAY
public static final DayOfWeek TUESDAY
The singleton instance for the day-of-week of Tuesday. This has the numeric value of2
.
-
WEDNESDAY
public static final DayOfWeek WEDNESDAY
The singleton instance for the day-of-week of Wednesday. This has the numeric value of3
.
-
THURSDAY
public static final DayOfWeek THURSDAY
The singleton instance for the day-of-week of Thursday. This has the numeric value of4
.
-
FRIDAY
public static final DayOfWeek FRIDAY
The singleton instance for the day-of-week of Friday. This has the numeric value of5
.
-
SATURDAY
public static final DayOfWeek SATURDAY
The singleton instance for the day-of-week of Saturday. This has the numeric value of6
.
-
SUNDAY
public static final DayOfWeek SUNDAY
The singleton instance for the day-of-week of Sunday. This has the numeric value of7
.
-
-
Method Detail
-
values
public static DayOfWeek[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (DayOfWeek c : DayOfWeek.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static DayOfWeek valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (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:
java.lang.IllegalArgumentException
- if this enum type has no constant with the specified namejava.lang.NullPointerException
- if the argument is null
-
of
public static DayOfWeek of(int dayOfWeek)
Obtains an instance ofDayOfWeek
from anint
value.DayOfWeek
is an enum representing the 7 days of the week. This factory allows the enum to be obtained from theint
value. Theint
value follows the ISO-8601 standard, from 1 (Monday) to 7 (Sunday).An exception is thrown if the value is invalid. The exception uses the
ISOChronology
day-of-week rule to indicate the failed rule.- Parameters:
dayOfWeek
- the day-of-week to represent, from 1 (Monday) to 7 (Sunday)- Returns:
- the DayOfWeek singleton, never null
- Throws:
IllegalCalendarFieldValueException
- if the day-of-week is invalid
-
firstDayOfWeekFor
public static DayOfWeek firstDayOfWeekFor(java.util.Locale locale)
Returns theDayOfWeek
instance that corresponds to the first day-of-week for a givenlocale
.If there is no information for a locale,
MONDAY
is returned.- Parameters:
locale
- the locale to use, not null- Returns:
- the DayOfWeek singleton, never null
-
getValue
public int getValue()
Gets the day-of-weekint
value.The values are numbered following the ISO-8601 standard, from 1 (Monday) to 7 (Sunday).
- Returns:
- the day-of-week, from 1 (Monday) to 7 (Sunday)
-
get
public <T> T get(CalendricalRule<T> rule)
Gets the value of the specified calendrical rule.This returns the one of the day-of-week values if the type of the rule is
DayOfWeek
. Other rules will returnnull
.- Specified by:
get
in interfaceCalendrical
- Parameters:
rule
- the rule to use, not null- Returns:
- the value for the rule, null if the value cannot be returned
-
getShortText
public java.lang.String getShortText(java.util.Locale locale)
Gets the short textual representation of this day-of-week, such as 'Mon' or 'Fri'.This method is notionally specific to
ISOChronology
as it uses the day-of-week rule to obtain the text. However, it is expected that the text will be equivalent for all day-of-week rules, thus this aspect of the implementation should be irrelevant to applications.If there is no textual mapping for the locale, then the ISO-8601
value
is returned as perInteger.toString()
.- Parameters:
locale
- the locale to use, not null- Returns:
- the short text value of the day-of-week, never null
-
getText
public java.lang.String getText(java.util.Locale locale)
Gets the full textual representation of this day-of-week, such as 'Monday' or 'Friday'.This method is notionally specific to
ISOChronology
as it uses the day-of-week rule to obtain the text. However, it is expected that the text will be equivalent for all day-of-week rules, thus this aspect of the implementation should be irrelevant to applications.If there is no textual mapping for the locale, then the ISO-8601
value
is returned as perInteger.toString()
.- Parameters:
locale
- the locale to use, not null- Returns:
- the full text value of the day-of-week, never null
-
isMonday
public boolean isMonday()
Is this instance representing Monday.- Returns:
- true if this instance represents Monday
-
isTuesday
public boolean isTuesday()
Is this instance representing Tuesday.- Returns:
- true if this instance represents Tuesday
-
isWednesday
public boolean isWednesday()
Is this instance representing Wednesday.- Returns:
- true if this instance represents Wednesday
-
isThursday
public boolean isThursday()
Is this instance representing Thursday.- Returns:
- true if this instance represents Thursday
-
isFriday
public boolean isFriday()
Is this instance representing Friday.- Returns:
- true if this instance represents Friday
-
isSaturday
public boolean isSaturday()
Is this instance representing Saturday.- Returns:
- true if this instance represents Saturday
-
isSunday
public boolean isSunday()
Is this instance representing Sunday.- Returns:
- true if this instance represents Sunday
-
next
public DayOfWeek next()
Gets the next day-of-week.This calculates based on the time-line, thus it rolls around the end of the week. The next day after Sunday is Monday.
- Returns:
- the next day-of-week, never null
-
previous
public DayOfWeek previous()
Gets the previous day-of-week.This calculates based on the time-line, thus it rolls around the end of the week. The previous day before Monday is Sunday.
- Returns:
- the previous day-of-week, never null
-
roll
public DayOfWeek roll(int days)
Rolls the day-of-week, adding the specified number of days.This calculates based on the time-line, thus it rolls around the end of the week from Sunday to Monday. The days to roll by may be negative.
This instance is immutable and unaffected by this method call.
- Parameters:
days
- the days to roll by, positive or negative- Returns:
- the resulting day-of-week, never null
-
-