Enum Class AmPmOfDay

java.lang.Object
java.lang.Enum<AmPmOfDay>
javax.time.calendar.AmPmOfDay
All Implemented Interfaces:
Serializable, Comparable<AmPmOfDay>, Constable, 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. 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
    Enum Constant
    Description
    The singleton instance for the morning, AM - ante meridiem.
    The singleton instance for the afternoon, PM - post meridiem.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
     
  • Method Summary

    Modifier and Type
    Method
    Description
    <T> T
    Gets the value of the specified calendrical rule.
    Gets the short textual representation of this AM/PM, such as 'AM' or 'PM'.
    getText(Locale locale)
    Gets the full textual representation of this AM/PM, such as 'AM' or 'PM'.
    int
    Gets the AM/PM int value.
    boolean
    Is this instance representing AM (ante-meridiem).
    boolean
    Is this instance representing PM (post-meridiem).
    static AmPmOfDay
    of(int amPmOfDay)
    Obtains an instance of AmPmOfDay from an int value.
    static AmPmOfDay
    Returns the enum constant of this class with the specified name.
    static AmPmOfDay[]
    Returns an array containing the constants of this enum class, in the order they are declared.

    Methods inherited from class java.lang.Object

    getClass, notify, notifyAll, wait, wait, wait
  • Enum Constant Details

    • 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.
  • Constructor Details

    • AmPmOfDay

      private AmPmOfDay()
  • Method Details

    • values

      public static AmPmOfDay[] 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

      public static AmPmOfDay valueOf(String name)
      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 name
      NullPointerException - if the argument is 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 AmPmOfDay singleton, never null
      Throws:
      IllegalCalendarFieldValueException - if the value is invalid
    • 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)
    • 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 return null.

      Specified by:
      get in interface Calendrical
      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