Enum Class AmPmOfDay
- All Implemented Interfaces:
Serializable
,Comparable<AmPmOfDay>
,Constable
,Calendrical
AmPmOfDay
is an enum representing the half-day concepts of AM and PM.
AM is defined as from 00:00 to 11:59, while PM is defined from 12:00 to 23:59.
The calendrical framework requires date-time fields to have an int
value.
The int
value follows Calendar
, assigning 0 to AM and 1 to PM.
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 AmPmOfDay
.
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 AM/PM concept.
Note that the implementation of DateTimeFieldRule
may vary by calendar system.
AmPmOfDay 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 Constants -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T> T
get
(CalendricalRule<T> rule) Gets the value of the specified calendrical rule.getShortText
(Locale locale) Gets the short textual representation of this AM/PM, such as 'AM' or 'PM'.Gets the full textual representation of this AM/PM, such as 'AM' or 'PM'.int
getValue()
Gets the AM/PMint
value.boolean
isAm()
Is this instance representing AM (ante-meridiem).boolean
isPm()
Is this instance representing PM (post-meridiem).static AmPmOfDay
of
(int amPmOfDay) Obtains an instance ofAmPmOfDay
from anint
value.static AmPmOfDay
Returns the enum constant of this class with the specified name.static AmPmOfDay[]
values()
Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
AM
The singleton instance for the morning, AM - ante meridiem. This has the numeric value of0
. -
PM
The singleton instance for the afternoon, PM - post meridiem. This has the numeric value of1
.
-
-
Constructor Details
-
AmPmOfDay
private AmPmOfDay()
-
-
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 ofAmPmOfDay
from anint
value.AmPmOfDay
is an enum representing before and after midday. This factory allows the enum to be obtained from theint
value. Theint
value followsCalendar
, assigning 0 to AM and 1 to PM.An exception is thrown if the value is invalid. The exception uses the
ISOChronology
AM/PM rule to indicate the failed rule.- Parameters:
amPmOfDay
- the AM/PM value to represent, from 0 (AM) to 1 (PM)- Returns:
- the AmPmOfDay singleton, never null
- Throws:
IllegalCalendarFieldValueException
- if the value is invalid
-
getValue
public int getValue()Gets the AM/PMint
value.The values are numbered following
Calendar
, assigning 0 to AM and 1 to PM.- Returns:
- the AM/PM value, from 0 (AM) to 1 (PM)
-
get
Gets the value of the specified calendrical rule.This returns the one of the AM/PM values if the type of the rule is
AmPmOfDay
. 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 AM/PM, such as 'AM' or 'PM'.This method is notionally specific to
ISOChronology
as it uses the AM/PM rule to obtain the text. However, it is expected that the text will be equivalent for all AM/PM 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 AM/PM, never null
-
getText
Gets the full textual representation of this AM/PM, such as 'AM' or 'PM'.This method is notionally specific to
ISOChronology
as it uses the AM/PM rule to obtain the text. However, it is expected that the text will be equivalent for all AM/PM 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 long text value of the AM/PM, never null
-
isAm
public boolean isAm()Is this instance representing AM (ante-meridiem).- Returns:
- true if this instance represents AM
-
isPm
public boolean isPm()Is this instance representing PM (post-meridiem).- Returns:
- true if this instance represents PM
-