javax.time.calendar
Enum MonthOfYear

java.lang.Object
  extended by java.lang.Enum<MonthOfYear>
      extended by javax.time.calendar.MonthOfYear
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<MonthOfYear>, Calendrical

public enum MonthOfYear
extends java.lang.Enum<MonthOfYear>
implements Calendrical

A month-of-year, such as 'July'.

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.

Author:
Michael Nascimento Santos, Stephen Colebourne

Enum Constant Summary
APRIL
          The singleton instance for the month of April with 30 days.
AUGUST
          The singleton instance for the month of August with 31 days.
DECEMBER
          The singleton instance for the month of December with 31 days.
FEBRUARY
          The singleton instance for the month of February with 28 days, or 29 in a leap year.
JANUARY
          The singleton instance for the month of January with 31 days.
JULY
          The singleton instance for the month of July with 31 days.
JUNE
          The singleton instance for the month of June with 30 days.
MARCH
          The singleton instance for the month of March with 31 days.
MAY
          The singleton instance for the month of May with 31 days.
NOVEMBER
          The singleton instance for the month of November with 30 days.
OCTOBER
          The singleton instance for the month of October with 31 days.
SEPTEMBER
          The singleton instance for the month of September with 30 days.
 
Method Summary
<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 getMonthOfQuarter()
          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.
 QuarterOfYear getQuarterOfYear()
          Gets the quarter that this month falls in.
 java.lang.String getShortText(java.util.Locale locale)
          Gets the short textual representation of this month-of-year, such as 'Jan' or 'Dec'.
 java.lang.String getText(java.util.Locale locale)
          Gets the full textual representation of this month-of-year, such as 'January' or 'December'.
 int getValue()
          Gets the month-of-year int value.
 boolean isApril()
          Is this instance representing April.
 boolean isAugust()
          Is this instance representing August.
 boolean isDecember()
          Is this instance representing December.
 boolean isFebruary()
          Is this instance representing February.
 boolean isJanuary()
          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 isNovember()
          Is this instance representing November.
 boolean isOctober()
          Is this instance representing October.
 boolean isSeptember()
          Is this instance representing September.
 int lengthInDays(boolean leapYear)
          Gets the length of this month in days.
 int maxLengthInDays()
          Gets the maximum length of this month in days.
 int minLengthInDays()
          Gets the minimum length of this month in days.
 MonthOfYear next()
          Gets the next month-of-year.
static MonthOfYear of(int monthOfYear)
          Obtains an instance of MonthOfYear from an int value.
 MonthOfYear previous()
          Gets the previous month-of-year.
 MonthOfYear roll(int months)
          Rolls the month-of-year, adding the specified number of months.
static MonthOfYear valueOf(java.lang.String name)
          Returns the enum constant of this type with the specified name.
static MonthOfYear[] values()
          Returns an array containing the constants of this enum type, in the order they are declared.
 
Methods inherited from class java.lang.Enum
clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Enum Constant Detail

JANUARY

public static final MonthOfYear JANUARY
The singleton instance for the month of January with 31 days. This has the numeric value of 1.


FEBRUARY

public static final MonthOfYear FEBRUARY
The singleton instance for the month of February with 28 days, or 29 in a leap year. This has the numeric value of 2.


MARCH

public static final MonthOfYear MARCH
The singleton instance for the month of March with 31 days. This has the numeric value of 3.


APRIL

public static final MonthOfYear APRIL
The singleton instance for the month of April with 30 days. This has the numeric value of 4.


MAY

public static final MonthOfYear MAY
The singleton instance for the month of May with 31 days. This has the numeric value of 5.


JUNE

public static final MonthOfYear JUNE
The singleton instance for the month of June with 30 days. This has the numeric value of 6.


JULY

public static final MonthOfYear JULY
The singleton instance for the month of July with 31 days. This has the numeric value of 7.


AUGUST

public static final MonthOfYear AUGUST
The singleton instance for the month of August with 31 days. This has the numeric value of 8.


SEPTEMBER

public static final MonthOfYear SEPTEMBER
The singleton instance for the month of September with 30 days. This has the numeric value of 9.


OCTOBER

public static final MonthOfYear OCTOBER
The singleton instance for the month of October with 31 days. This has the numeric value of 10.


NOVEMBER

public static final MonthOfYear NOVEMBER
The singleton instance for the month of November with 30 days. This has the numeric value of 11.


DECEMBER

public static final MonthOfYear DECEMBER
The singleton instance for the month of December with 31 days. This has the numeric value of 12.

Method Detail

values

public static MonthOfYear[] 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 (MonthOfYear c : MonthOfYear.values())
    System.out.println(c);

Returns:
an array containing the constants of this enum type, in the order they are declared

valueOf

public static MonthOfYear 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 name
java.lang.NullPointerException - if the argument is null

of

public static MonthOfYear of(int monthOfYear)
Obtains an instance of MonthOfYear from an int value.

MonthOfYear is an enum representing the 12 months of the year. This factory allows the enum to be obtained from the int value. The int 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-year int 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

public <T> T get(CalendricalRule<T> rule)
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 return null.

Specified by:
get in interface Calendrical
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 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

public java.lang.String getText(java.util.Locale locale)
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

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

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

public MonthOfYear roll(int months)
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

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