javax.time.calendar
Enum AmPmOfDay

java.lang.Object
  extended by java.lang.Enum<AmPmOfDay>
      extended by javax.time.calendar.AmPmOfDay
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<AmPmOfDay>, Calendrical, CalendricalMatcher

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

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. 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 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
AM
          The singleton instance for the morning, AM - ante meridiem.
PM
          The singleton instance for the afternoon, PM - post meridiem.
 
Method Summary
static AmPmOfDay from(Calendrical... calendricals)
          Obtains an instance of AmPmOfDay from a set of calendricals.
<T> T
get(CalendricalRule<T> ruleToDerive)
          Gets the value of the specified calendrical rule.
 java.lang.String getText(TextStyle style, java.util.Locale locale)
          Gets the textual representation, such as 'AM' or 'PM'.
 int getValue()
          Gets the AM/PM int value.
 boolean matchesCalendrical(Calendrical calendrical)
          Checks if the AM/PM extracted from the calendrical matches this.
static AmPmOfDay of(int amPmOfDay)
          Obtains an instance of AmPmOfDay from an int value.
static CalendricalRule<AmPmOfDay> rule()
          Gets the rule for AmPmOfDay.
 DateTimeField toField()
          Converts this AM/PM to an equivalent field.
static AmPmOfDay valueOf(java.lang.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.
 
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

AM

public static final AmPmOfDay AM
The singleton instance for the morning, AM - ante meridiem. This has the numeric value of 0.


PM

public static final AmPmOfDay PM
The singleton instance for the afternoon, PM - post meridiem. This has the numeric value of 1.

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(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<AmPmOfDay> rule()
Gets the rule for AmPmOfDay.

This rule is a calendrical rule based on AmPmOfDay. The equivalent date-time rule is ISODateTimeRule.AMPM_OF_DAY.

Returns:
the rule for the am-pm-of-day, not null

of

public static AmPmOfDay of(int amPmOfDay)
Obtains an instance of 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.

Parameters:
amPmOfDay - the AM/PM value to represent, from 0 (AM) to 1 (PM)
Returns:
the AM/PM, not null
Throws:
IllegalCalendarFieldValueException - if the value is invalid

from

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

A calendrical represents some form of date and time information. This method combines the input calendricals into AM/PM.

Parameters:
calendricals - the calendricals to create AM/PM from, no nulls, not null
Returns:
the AM/PM, not null
Throws:
CalendricalException - if unable to merge to AM/PM

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.AMPM_OF_DAY 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 AM/PM int 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)

getText

public java.lang.String getText(TextStyle style,
                                java.util.Locale locale)
Gets the textual representation, 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 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 AM/PM, not null

matchesCalendrical

public boolean matchesCalendrical(Calendrical calendrical)
Checks if the AM/PM 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 AM/PM to an equivalent field.

The field is based on ISODateTimeRule.AMPM_OF_DAY.

Returns:
the equivalent AM/PM field, not null