Enum AmPmOfDay
- java.lang.Object
-
- java.lang.Enum<AmPmOfDay>
-
- javax.time.calendar.AmPmOfDay
-
- All Implemented Interfaces:
Serializable
,Comparable<AmPmOfDay>
,Calendrical
public enum AmPmOfDay extends Enum<AmPmOfDay> implements Calendrical
A half-day before or after midday, with the values 'AM' and 'PM'.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. Theint
value followsCalendar
, assigning 0 to AM and 1 to PM. It is recommended that applications use the enum rather than theint
value to ensure code clarity.Do not use
ordinal()
to obtain the numeric representation ofAmPmOfDay
. UsegetValue()
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.
- Author:
- Michael Nascimento Santos, Stephen Colebourne
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> T
get(CalendricalRule<T> rule)
Gets the value of the specified calendrical rule.String
getShortText(Locale locale)
Gets the short textual representation of this AM/PM, such as 'AM' or 'PM'.String
getText(Locale locale)
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
valueOf(String name)
Returns the enum constant of this type with the specified name.static AmPmOfDay[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.
-
-
-
Method Detail
-
values
public static AmPmOfDay[] 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 (AmPmOfDay c : AmPmOfDay.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static AmPmOfDay valueOf(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:
IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is null
-
of
public static AmPmOfDay of(int amPmOfDay)
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
public <T> T get(CalendricalRule<T> rule)
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
public String getShortText(Locale locale)
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
public String getText(Locale locale)
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
-
-