Enum Class MonthOfYear
- All Implemented Interfaces:
Serializable
,Comparable<MonthOfYear>
,Constable
,Calendrical
MonthOfYear
is an enum representing the 12 months of the year -
January, February, March, April, May, June, July, August, September, October,
November and December.
In addition to the textual enum name, each month-of-year has an int
value.
The int
value follows normal usage and the ISO-8601 standard,
from 1 (January) to 12 (December). It is recommended that applications use the enum
rather than the int
value to ensure code clarity.
Do not use ordinal()
to obtain the numeric representation of MonthOfYear
.
Use getValue()
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 month-of-year
concept with a twelve month year where the names and month lengths are equivalent to
those defined. Note that the implementation of DateTimeFieldRule
for month-of-year
may vary by calendar system.
MonthOfYear is an immutable and thread-safe enum.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>>
-
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionThe singleton instance for the month of April with 30 days.The singleton instance for the month of August with 31 days.The singleton instance for the month of December with 31 days.The singleton instance for the month of February with 28 days, or 29 in a leap year.The singleton instance for the month of January with 31 days.The singleton instance for the month of July with 31 days.The singleton instance for the month of June with 30 days.The singleton instance for the month of March with 31 days.The singleton instance for the month of May with 31 days.The singleton instance for the month of November with 30 days.The singleton instance for the month of October with 31 days.The singleton instance for the month of September with 30 days. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T> T
get
(CalendricalRule<T> rule) Gets the value of the specified calendrical rule.int
getLastDayOfMonth
(boolean leapYear) Gets the day-of-month for last day of this month.int
getMonthEndDayOfYear
(boolean leapYear) Gets the day-of-year for the last day of this month.int
Gets the index of the month within the quarter.int
getMonthStartDayOfYear
(boolean leapYear) Gets the day-of-year for the first day of this month.Gets the quarter that this month falls in.getShortText
(Locale locale) Gets the short textual representation of this month-of-year, such as 'Jan' or 'Dec'.Gets the full textual representation of this month-of-year, such as 'January' or 'December'.int
getValue()
Gets the month-of-yearint
value.boolean
isApril()
Is this instance representing April.boolean
isAugust()
Is this instance representing August.boolean
Is this instance representing December.boolean
Is this instance representing February.boolean
Is this instance representing January.boolean
isJuly()
Is this instance representing July.boolean
isJune()
Is this instance representing June.boolean
isMarch()
Is this instance representing March.boolean
isMay()
Is this instance representing May.boolean
Is this instance representing November.boolean
Is this instance representing October.boolean
Is this instance representing September.int
lengthInDays
(boolean leapYear) Gets the length of this month in days.int
Gets the maximum length of this month in days.int
Gets the minimum length of this month in days.next()
Gets the next month-of-year.static MonthOfYear
of
(int monthOfYear) Obtains an instance ofMonthOfYear
from anint
value.previous()
Gets the previous month-of-year.roll
(int months) Rolls the month-of-year, adding the specified number of months.static MonthOfYear
Returns the enum constant of this class with the specified name.static MonthOfYear[]
values()
Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
JANUARY
The singleton instance for the month of January with 31 days. This has the numeric value of1
. -
FEBRUARY
The singleton instance for the month of February with 28 days, or 29 in a leap year. This has the numeric value of2
. -
MARCH
The singleton instance for the month of March with 31 days. This has the numeric value of3
. -
APRIL
The singleton instance for the month of April with 30 days. This has the numeric value of4
. -
MAY
The singleton instance for the month of May with 31 days. This has the numeric value of5
. -
JUNE
The singleton instance for the month of June with 30 days. This has the numeric value of6
. -
JULY
The singleton instance for the month of July with 31 days. This has the numeric value of7
. -
AUGUST
The singleton instance for the month of August with 31 days. This has the numeric value of8
. -
SEPTEMBER
The singleton instance for the month of September with 30 days. This has the numeric value of9
. -
OCTOBER
The singleton instance for the month of October with 31 days. This has the numeric value of10
. -
NOVEMBER
The singleton instance for the month of November with 30 days. This has the numeric value of11
. -
DECEMBER
The singleton instance for the month of December with 31 days. This has the numeric value of12
.
-
-
Constructor Details
-
MonthOfYear
private MonthOfYear()
-
-
Method Details
-
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
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 nameNullPointerException
- if the argument is null
-
of
Obtains an instance ofMonthOfYear
from anint
value.MonthOfYear
is an enum representing the 12 months of the year. This factory allows the enum to be obtained from theint
value. Theint
value follows the ISO-8601 standard, from 1 (January) to 12 (December).An exception is thrown if the value is invalid. The exception uses the
ISOChronology
month-of-year rule to indicate the failed rule.- Parameters:
monthOfYear
- the month-of-year to represent, from 1 (January) to 12 (December)- Returns:
- the MonthOfYear singleton, never null
- Throws:
IllegalCalendarFieldValueException
- if the month-of-year is invalid
-
getValue
public int getValue()Gets the month-of-yearint
value.The values are numbered following the ISO-8601 standard, from 1 (January) to 12 (December).
- Returns:
- the month-of-year, from 1 (January) to 12 (December)
-
get
Gets the value of the specified calendrical rule.This returns the one of the month values if the type of the rule is
MonthOfYear
. 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
Gets the short textual representation of this month-of-year, such as 'Jan' or 'Dec'.This method is notionally specific to
ISOChronology
as it uses the month-of-year rule to obtain the text. However, it is expected that the text will be equivalent for all month-of-year rules, thus this aspect of the implementation should be irrelevant to applications.If there is no textual mapping for the locale, then the value is returned as per
Integer.toString()
.- Parameters:
locale
- the locale to use, not null- Returns:
- the short text value of the month-of-year, never null
-
getText
Gets the full textual representation of this month-of-year, such as 'January' or 'December'.This method is notionally specific to
ISOChronology
as it uses the month-of-year rule to obtain the text. However, it is expected that the text will be equivalent for all month-of-year rules, thus this aspect of the implementation should be irrelevant to applications.If there is no textual mapping for the locale, then the value is returned as per
Integer.toString()
.- Parameters:
locale
- the locale to use, not null- Returns:
- the full text value of the month-of-year, never null
-
isJanuary
public boolean isJanuary()Is this instance representing January.- Returns:
- true if this instance represents January
-
isFebruary
public boolean isFebruary()Is this instance representing February.- Returns:
- true if this instance represents February
-
isMarch
public boolean isMarch()Is this instance representing March.- Returns:
- true if this instance represents March
-
isApril
public boolean isApril()Is this instance representing April.- Returns:
- true if this instance represents April
-
isMay
public boolean isMay()Is this instance representing May.- Returns:
- true if this instance represents May
-
isJune
public boolean isJune()Is this instance representing June.- Returns:
- true if this instance represents June
-
isJuly
public boolean isJuly()Is this instance representing July.- Returns:
- true if this instance represents July
-
isAugust
public boolean isAugust()Is this instance representing August.- Returns:
- true if this instance represents August
-
isSeptember
public boolean isSeptember()Is this instance representing September.- Returns:
- true if this instance represents September
-
isOctober
public boolean isOctober()Is this instance representing October.- Returns:
- true if this instance represents October
-
isNovember
public boolean isNovember()Is this instance representing November.- Returns:
- true if this instance represents November
-
isDecember
public boolean isDecember()Is this instance representing December.- Returns:
- true if this instance represents December
-
next
Gets the next month-of-year.This calculates based on the time-line, thus it rolls around the end of the year. The next month after December is January.
- Returns:
- the next month-of-year, never null
-
previous
Gets the previous month-of-year.This calculates based on the time-line, thus it rolls around the end of the year. The previous month before January is December.
- Returns:
- the previous month-of-year, never null
-
roll
Rolls the month-of-year, adding the specified number of months.This calculates based on the time-line, thus it rolls around the end of the year from December to January. The months to roll by may be negative.
This instance is immutable and unaffected by this method call.
- Parameters:
months
- the months to roll by, positive or negative- Returns:
- the resulting month-of-year, never null
-
lengthInDays
public int lengthInDays(boolean leapYear) Gets the length of this month in days.This takes a flag to determine whether to return the length for a leap year or not.
February has 28 days in a standard year and 29 days in a leap year. April, June, September and November have 30 days. All other months have 31 days.
- Parameters:
leapYear
- true if the length is required for a leap year- Returns:
- the length of this month in days, from 28 to 31
-
minLengthInDays
public int minLengthInDays()Gets the minimum length of this month in days.February has a minimum length of 28 days. April, June, September and November have 30 days. All other months have 31 days.
- Returns:
- the minimum length of this month in days, from 28 to 31
-
maxLengthInDays
public int maxLengthInDays()Gets the maximum length of this month in days.February has a maximum length of 29 days. April, June, September and November have 30 days. All other months have 31 days.
- Returns:
- the maximum length of this month in days, from 29 to 31
-
getLastDayOfMonth
public int getLastDayOfMonth(boolean leapYear) Gets the day-of-month for last day of this month.This is a synonym for
lengthInDays(boolean)
and exists to provide a more meaningful API.- Parameters:
leapYear
- true if the length is required for a leap year- Returns:
- the last day of this month, from 28 to 31
-
getMonthStartDayOfYear
public int getMonthStartDayOfYear(boolean leapYear) Gets the day-of-year for the first day of this month.This returns the day-of-year that this month begins on, using the leap year flag to determine the length of February.
- Parameters:
leapYear
- true if the length is required for a leap year- Returns:
- the last day of this month, from 1 to 335
-
getMonthEndDayOfYear
public int getMonthEndDayOfYear(boolean leapYear) Gets the day-of-year for the last day of this month.This returns the day-of-year that this month ends on, using the leap year flag to determine the length of February.
- Parameters:
leapYear
- true if the length is required for a leap year- Returns:
- the last day of this month, from 31 to 366
-
getQuarterOfYear
Gets the quarter that this month falls in.January to March are Q1, April to June are Q2, July to September are Q3 and October to December are Q4.
- Returns:
- the quarter-of-year, never null
-
getMonthOfQuarter
public int getMonthOfQuarter()Gets the index of the month within the quarter.January, April, July and October will return 1. February, May, August and November will return 2. March, June, September and December will return 3.
- Returns:
- the month of season, from 1 to 3
-