Package net.time4j

Enum Class Meridiem

All Implemented Interfaces:
Serializable, Comparable<Meridiem>, java.lang.constant.Constable, Predicate<WallTime>, ChronoCondition<WallTime>

public enum Meridiem extends Enum<Meridiem> implements ChronoCondition<WallTime>

Represents the half day relative to noon.

Author:
Meno Hochschild
  • Enum Constant Details

    • AM

      public static final Meridiem AM

      Marks the wall time from midnight (at start of day) until before noon (ante meridiem).

      The numerical value is 0.

    • PM

      public static final Meridiem PM

      Marks the wall time at or after noon (post meridiem).

      The numerical value is 1.

  • Method Details

    • values

      public static Meridiem[] 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 Meridiem 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
    • ofHour

      public static Meridiem ofHour(int hour)

      Calculates the meridiem value dependent on given hour of day.

      Parameters:
      hour - ISO-hour in the range 0 <= hour <= 24
      Returns:
      half of day (ante meridiem or post meridiem)
      Throws:
      IllegalArgumentException - if the hour is out of range
      See Also:
      PlainTime.AM_PM_OF_DAY
    • getDisplayName

      public String getDisplayName(Locale locale)

      Equivalent to the expression getDisplayName(locale, TextWidth.WIDE, OutputContext.FORMAT).

      Parameters:
      locale - language of text to be printed
      Returns:
      localized text in given language
    • getDisplayName

      public String getDisplayName(Locale locale, TextWidth width, OutputContext context)

      Gets the description text dependent on the locale and style parameters.

      The second argument controls the width of description while the third argument is only relevant for languages which make a difference between stand-alone forms and embedded text forms (does not matter in English).

      Parameters:
      locale - language setting
      width - text width
      context - output context
      Returns:
      descriptive text for given locale and style (never null)
      Since:
      3.35/4.30
    • parse

      public static Meridiem parse(CharSequence text, Locale locale, TextWidth width, OutputContext context) throws ParseException

      Tries to interprete given text as AM/PM.

      The strings "am", "AM", "pm", "PM" are always understood.

      Parameters:
      text - the text to be parsed
      locale - language setting
      width - expected text width
      context - expected output context
      Returns:
      the parsed meridiem if successful
      Throws:
      ParseException - if parsing fails
      Since:
      3.35/4.30
      See Also:
      getDisplayName(Locale, TextWidth, OutputContext)
    • test

      public boolean test(WallTime context)
      Description copied from interface: ChronoCondition

      Decides if given context matches this condition.

      Due to better readability it is recommended to use following equivalent approach instead of this method::

        import static net.time4j.Weekday.SATURDAY;
        import static net.time4j.Month.JANUARY;
      
        PlainDate date = PlainDate.of(2014, JANUARY, 25);
        System.out.println(SATURDAY.test(date)); // direct use
        System.out.println(date.matches(SATURDAY)); // recommended callback
       
      Specified by:
      test in interface ChronoCondition<WallTime>
      Specified by:
      test in interface Predicate<WallTime>
      Parameters:
      context - context as base of testing this condition
      Returns:
      true if given time context matches this condition else false