public enum AmPmOfDay extends Enum<AmPmOfDay> implements 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.
Enum Constant and Description |
---|
AM
The singleton instance for the morning, AM - ante meridiem.
|
PM
The singleton instance for the afternoon, PM - post meridiem.
|
Modifier and Type | Method and 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/PM
int 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 of
AmPmOfDay from an int 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.
|
public static final AmPmOfDay AM
0
.public static final AmPmOfDay PM
1
.public static AmPmOfDay[] values()
for (AmPmOfDay c : AmPmOfDay.values()) System.out.println(c);
public static AmPmOfDay valueOf(String name)
name
- the name of the enum constant to be returned.IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is nullpublic static AmPmOfDay of(int amPmOfDay)
AmPmOfDay
from an int
value.
AmPmOfDay
is an enum representing before and after midday.
This factory allows the enum to be obtained from the int
value.
The int
value follows Calendar
, 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.
amPmOfDay
- the AM/PM value to represent, from 0 (AM) to 1 (PM)IllegalCalendarFieldValueException
- if the value is invalidpublic int getValue()
int
value.
The values are numbered following Calendar
, assigning 0 to AM and 1 to PM.
public <T> T get(CalendricalRule<T> rule)
This returns the one of the AM/PM values if the type of the rule
is AmPmOfDay
. Other rules will return null
.
get
in interface Calendrical
rule
- the rule to use, not nullpublic String getShortText(Locale locale)
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()
.
locale
- the locale to use, not nullpublic String getText(Locale locale)
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()
.
locale
- the locale to use, not nullpublic boolean isAm()
public boolean isPm()
Copyright © 2014. All rights reserved.