Month

A month-of-year, such as 'July'. !(p) {@code Month} is an enum representing the 12 months of the year - January, February, March, April, May, June, July, August, September, October, November and December. !(p) In addition to the textual enum name, each month-of-year has an {@code int} value. The {@code 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 {@code int} value to ensure code clarity. !(p) !(b)Do not use {@code ordinal()} to obtain the numeric representation of {@code Month}. Use {@code getValue()} instead.</b> !(p) 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-8601 calendar system.

@implSpec This is an immutable and thread-safe enum.

@since 1.8

Constructors

this
this(int ordinal, string name)
Undocumented in source.

Members

Aliases

ENUMS
alias ENUMS = values
Undocumented in source.

Functions

adjustInto
Temporal adjustInto(Temporal temporal)

Adjusts the specified temporal object to have this month-of-year. !(p) This returns a temporal object of the same observable type as the input with the month-of-year changed to be the same as this. !(p) The adjustment is equivalent to using {@link Temporal#_with(TemporalField, long)} passing {@link ChronoField#MONTH_OF_YEAR} as the field. If the specified temporal object does not use the ISO calendar system then a {@code DateTimeException} is thrown. !(p) In most cases, it is clearer to reverse the calling pattern by using {@link Temporal#_with(TemporalAdjuster)}: !(pre) // these two lines are equivalent, but the second approach is recommended temporal = thisMonth.adjustInto(temporal); temporal = temporal._with(thisMonth); </pre> !(p) For example, given a date _in May, the following are output: !(pre) dateInMay._with(JANUARY); // four months earlier dateInMay._with(APRIL); // one months earlier dateInMay._with(MAY); // same date dateInMay._with(JUNE); // one month later dateInMay._with(DECEMBER); // seven months later </pre> !(p) This instance is immutable and unaffected by this method call.

firstDayOfYear
int firstDayOfYear(bool leapYear)

Gets the day-of-year corresponding to the first day of this month. !(p) This returns the day-of-year that this month begins on, using the leap year flag to determine the length of February.

firstMonthOfQuarter
Month firstMonthOfQuarter()

Gets the month corresponding to the first month of this quarter. !(p) The year can be divided into four quarters. This method returns the first month of the quarter for the base month. January, February and March return January. April, May and June return April. July, August and September return July. October, November and December return October.

get
int get(TemporalField field)

Gets the value of the specified field from this month-of-year as an {@code int}. !(p) This queries this month for the value of the specified field. The returned value will always be within the valid range of values for the field. If it is not possible to return the value, because the field is not supported or for some other reason, an exception is thrown. !(p) If the field is {@link ChronoField#MONTH_OF_YEAR MONTH_OF_YEAR} then the value of the month-of-year, from 1 to 12, will be returned. All other {@code ChronoField} instances will throw an {@code UnsupportedTemporalTypeException}. !(p) If the field is not a {@code ChronoField}, then the result of this method is obtained by invoking {@code TemporalField.getFrom(TemporalAccessor)} passing {@code this} as the argument. Whether the value can be obtained, and what the value represents, is determined by the field.

getLong
long getLong(TemporalField field)

Gets the value of the specified field from this month-of-year as a {@code long}. !(p) This queries this month for the value of the specified field. If it is not possible to return the value, because the field is not supported or for some other reason, an exception is thrown. !(p) If the field is {@link ChronoField#MONTH_OF_YEAR MONTH_OF_YEAR} then the value of the month-of-year, from 1 to 12, will be returned. All other {@code ChronoField} instances will throw an {@code UnsupportedTemporalTypeException}. !(p) If the field is not a {@code ChronoField}, then the result of this method is obtained by invoking {@code TemporalField.getFrom(TemporalAccessor)} passing {@code this} as the argument. Whether the value can be obtained, and what the value represents, is determined by the field.

getValue
int getValue()

Gets the month-of-year {@code int} value. !(p) The values are numbered following the ISO-8601 standard, from 1 (January) to 12 (December).

isSupported
bool isSupported(TemporalField field)

Checks if the specified field is supported. !(p) This checks if this month-of-year can be queried for the specified field. If false, then calling the {@link #range(TemporalField) range} and {@link #get(TemporalField) get} methods will throw an exception. !(p) If the field is {@link ChronoField#MONTH_OF_YEAR MONTH_OF_YEAR} then this method returns true. All other {@code ChronoField} instances will return false. !(p) If the field is not a {@code ChronoField}, then the result of this method is obtained by invoking {@code TemporalField.isSupportedBy(TemporalAccessor)} passing {@code this} as the argument. Whether the field is supported is determined by the field.

length
int length(bool leapYear)

Gets the length of this month _in days. !(p) This takes a flag to determine whether to return the length for a leap year or not. !(p) 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.

maxLength
int maxLength()

Gets the maximum length of this month _in days. !(p) February has a maximum length of 29 days. April, June, September and November have 30 days. All other months have 31 days.

minLength
int minLength()

Gets the minimum length of this month _in days. !(p) February has a minimum length of 28 days. April, June, September and November have 30 days. All other months have 31 days.

minus
Month minus(long months)

Returns the month-of-year that is the specified number of months before this one. !(p) The calculation rolls around the start of the year from January to December. The specified period may be negative. !(p) This instance is immutable and unaffected by this method call.

plus
Month plus(long months)

Returns the month-of-year that is the specified number of months after this one. !(p) The calculation rolls around the end of the year from December to January. The specified period may be negative. !(p) This instance is immutable and unaffected by this method call.

query
R query(TemporalQuery!(R) query)

Queries this month-of-year using the specified query. !(p) This queries this month-of-year using the specified query strategy object. The {@code TemporalQuery} object defines the logic to be used to obtain the result. Read the documentation of the query to understand what the result of this method will be. !(p) The result of this method is obtained by invoking the {@link TemporalQuery#queryFrom(TemporalAccessor)} method on the specified query passing {@code this} as the argument.

range
ValueRange range(TemporalField field)

Gets the range of valid values for the specified field. !(p) The range object expresses the minimum and maximum valid values for a field. This month is used to enhance the accuracy of the returned range. If it is not possible to return the range, because the field is not supported or for some other reason, an exception is thrown. !(p) If the field is {@link ChronoField#MONTH_OF_YEAR MONTH_OF_YEAR} then the range of the month-of-year, from 1 to 12, will be returned. All other {@code ChronoField} instances will throw an {@code UnsupportedTemporalTypeException}. !(p) If the field is not a {@code ChronoField}, then the result of this method is obtained by invoking {@code TemporalField.rangeRefinedBy(TemporalAccessor)} passing {@code this} as the argument. Whether the range can be obtained is determined by the field.

super_get
int super_get(TemporalField field)
Undocumented in source. Be warned that the author may not have intended to support it.
super_query
R super_query(TemporalQuery!(R) query)
Undocumented in source. Be warned that the author may not have intended to support it.
super_range
ValueRange super_range(TemporalField field)
Undocumented in source. Be warned that the author may not have intended to support it.
toString
string toString()
Undocumented in source. Be warned that the author may not have intended to support it.

Static functions

APRIL
Month APRIL()

The singleton instance for the month of April with 30 days. This has the numeric value of {@code 4}.

AUGUST
Month AUGUST()

The singleton instance for the month of August with 31 days. This has the numeric value of {@code 8}.

DECEMBER
Month DECEMBER()

The singleton instance for the month of December with 31 days. This has the numeric value of {@code 12}.

FEBRUARY
Month FEBRUARY()

The singleton instance for the month of February with 28 days, or 29 _in a leap year. This has the numeric value of {@code 2}.

JANUARY
Month JANUARY()

The singleton instance for the month of January with 31 days. This has the numeric value of {@code 1}.

JULY
Month JULY()

The singleton instance for the month of July with 31 days. This has the numeric value of {@code 7}.

JUNE
Month JUNE()

The singleton instance for the month of June with 30 days. This has the numeric value of {@code 6}.

MARCH
Month MARCH()

The singleton instance for the month of March with 31 days. This has the numeric value of {@code 3}.

MAY
Month MAY()

The singleton instance for the month of May with 31 days. This has the numeric value of {@code 5}.

NOVEMBER
Month NOVEMBER()

The singleton instance for the month of November with 30 days. This has the numeric value of {@code 11}.

OCTOBER
Month OCTOBER()

The singleton instance for the month of October with 31 days. This has the numeric value of {@code 10}.

SEPTEMBER
Month SEPTEMBER()

The singleton instance for the month of September with 30 days. This has the numeric value of {@code 9}.

from
Month from(TemporalAccessor temporal)

Obtains an instance of {@code Month} from a temporal object. !(p) This obtains a month based on the specified temporal. A {@code TemporalAccessor} represents an arbitrary set of date and time information, which this factory converts to an instance of {@code Month}. !(p) The conversion extracts the {@link ChronoField#MONTH_OF_YEAR MONTH_OF_YEAR} field. The extraction is only permitted if the temporal object has an ISO chronology, or can be converted to a {@code LocalDate}. !(p) This method matches the signature of the functional interface {@link TemporalQuery} allowing it to be used as a query via method reference, {@code Month::from}.

of
Month of(int month)

Obtains an instance of {@code Month} from an {@code int} value. !(p) {@code Month} is an enum representing the 12 months of the year. This factory allows the enum to be obtained from the {@code int} value. The {@code int} value follows the ISO-8601 standard, from 1 (January) to 12 (December).

values
Month[] values()

Private cache of all the constants.

Inherited Members

From TemporalAccessor

isSupported
bool isSupported(TemporalField field)

Checks if the specified field is supported. !(p) This checks if the date-time can be queried for the specified field. If false, then calling the {@link #range(TemporalField) range} and {@link #get(TemporalField) get} methods will throw an exception.

range
ValueRange range(TemporalField field)

Gets the range of valid values for the specified field. !(p) All fields can be expressed as a {@code long} integer. This method returns an object that describes the valid range for that value. The value of this temporal object is used to enhance the accuracy of the returned range. If the date-time cannot return the range, because the field is unsupported or for some other reason, an exception will be thrown. !(p) Note that the result only describes the minimum and maximum valid values and it is important not to read too much into them. For example, there could be values within the range that are invalid for the field.

get
int get(TemporalField field)

Gets the value of the specified field as an {@code int}. !(p) This queries the date-time for the value of the specified field. The returned value will always be within the valid range of values for the field. If the date-time cannot return the value, because the field is unsupported or for some other reason, an exception will be thrown.

getLong
long getLong(TemporalField field)

Gets the value of the specified field as a {@code long}. !(p) This queries the date-time for the value of the specified field. The returned value may be outside the valid range of values for the field. If the date-time cannot return the value, because the field is unsupported or for some other reason, an exception will be thrown.

query
R query(TemporalQuery!(R) query)

Queries this date-time. !(p) This queries this date-time using the specified query strategy object. !(p) Queries are a key tool for extracting information from date-times. They exists to externalize the process of querying, permitting different approaches, as per the strategy design pattern. Examples might be a query that checks if the date is the day before February 29th _in a leap year, or calculates the number of days to your next birthday. !(p) The most common query implementations are method references, such as {@code LocalDate::from} and {@code ZoneId::from}. Additional implementations are provided as static methods on {@link TemporalQuery}.

toString
string toString()
Undocumented in source.

From TemporalAdjuster

adjustInto
Temporal adjustInto(Temporal temporal)

Adjusts the specified temporal object. !(p) This adjusts the specified temporal object using the logic encapsulated _in the implementing class. Examples might be an adjuster that sets the date avoiding weekends, or one that sets the date to the last day of the month. !(p) There are two equivalent ways of using this method. The first is to invoke this method directly. The second is to use {@link Temporal#_with(TemporalAdjuster)}: !(pre) // these two lines are equivalent, but the second approach is recommended temporal = thisAdjuster.adjustInto(temporal); temporal = temporal._with(thisAdjuster); </pre> It is recommended to use the second approach, {@code _with(TemporalAdjuster)}, as it is a lot clearer to read _in code.

Meta