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, CalendricalMatcher

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

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 defined exactly equivalent to the ISO calendar system.

This 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
static MonthOfYear from(Calendrical... calendricals)
          Obtains an instance of MonthOfYear from a set of calendricals.
<T> T
get(CalendricalRule<T> ruleToDerive)
          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 getText(TextStyle style, java.util.Locale locale)
          Gets the textual representation, such as 'Jan' or 'December'.
 int getValue()
          Gets the month-of-year int value.
 int lengthInDays(boolean leapYear)
          Gets the length of this month in days.
 boolean matchesCalendrical(Calendrical calendrical)
          Checks if the month-of-year extracted from the calendrical matches this.
 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 CalendricalRule<MonthOfYear> rule()
          Gets the rule for MonthOfYear.
 DateTimeField toField()
          Converts this month-of-year to an equivalent field.
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

rule

public static CalendricalRule<MonthOfYear> rule()
Gets the rule for MonthOfYear.

This rule is a calendrical rule based on MonthOfYear. The equivalent date-time rule is ISODateTimeRule.MONTH_OF_YEAR.

Returns:
the rule for the month-of-year, not 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, not null
Throws:
IllegalCalendarFieldValueException - if the month-of-year is invalid

from

public static MonthOfYear from(Calendrical... calendricals)
Obtains an instance of MonthOfYear from a set of calendricals.

A calendrical represents some form of date and time information. This method combines the input calendricals into a month-of-year.

Parameters:
calendricals - the calendricals to create a month-of-year from, no nulls, not null
Returns:
the month-of-year, not null
Throws:
CalendricalException - if unable to merge to a month-of-year

get

public <T> T get(CalendricalRule<T> ruleToDerive)
Gets the value of the specified calendrical rule.

This will only return a value for the ISODateTimeRule.MONTH_OF_YEAR rule, or something derivable from it.

Specified by:
get in interface Calendrical
Parameters:
ruleToDerive - the rule to derive, not null
Returns:
the value for the rule, null if the value cannot be returned

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)

getText

public java.lang.String getText(TextStyle style,
                                java.util.Locale locale)
Gets the textual representation, such as 'Jan' 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 no textual mapping is found then the numeric value is returned.

Parameters:
locale - the locale to use, not null
Returns:
the short text value of the month-of-year, not null

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, not 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, not 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, not 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, not 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

matchesCalendrical

public boolean matchesCalendrical(Calendrical calendrical)
Checks if the month-of-year extracted from the calendrical matches this.

This method implements the CalendricalMatcher interface. It is intended that applications use LocalDate.matches(javax.time.calendar.CalendricalMatcher) rather than this method.

Specified by:
matchesCalendrical in interface CalendricalMatcher
Parameters:
calendrical - the calendrical to match, not null
Returns:
true if the calendrical matches, false otherwise

toField

public DateTimeField toField()
Converts this month-of-year to an equivalent field.

The field is based on ISODateTimeRule.MONTH_OF_YEAR.

Returns:
the equivalent month-of-year field, not null