Package net.time4j

Class PlainTime

All Implemented Interfaces:
Serializable, Comparable<PlainTime>, TemporalAccessor, WallTime, ChronoDisplay, Temporal<PlainTime>, ThreetenAdapter, LocalizedPatternSupport

@CalendarType("iso8601") public final class PlainTime extends TimePoint<IsoTimeUnit,​PlainTime> implements WallTime, Temporal<PlainTime>, ThreetenAdapter, LocalizedPatternSupport

Represents a plain wall time without any timezone or date component as defined in ISO-8601 up to nanosecond precision.

This type also supports the special value 24:00 in its state space. That value means midnight at the end of day and can be both set and queried.

Following elements which are declared as constants are registered by this class:

Author:
Meno Hochschild
See Also:
Serialized Form
  • Field Details

    • COMPONENT

      public static final WallTimeElement COMPONENT

      Element with the wall time in the value range [T00:00:00,000000000] until [T24:00:00,000000000] (inclusive in the context of PlainTime else exclusive).

      Example of usage:

        PlainTimestamp tsp =
            ChronoFormatter.ofTimestampPattern("uuuu-MM-dd", PatternType.CLDR, Locale.getDefault())
                .withDefault(
                    PlainTime.COMPONENT,
                    PlainTime.midnightAtStartOfDay())
                .parse("2014-08-20");
        System.out.println(tsp); // output: 2014-08-20T00
       

      Note: This element does not define any base unit.

      Since:
      1.2
    • AM_PM_OF_DAY

      @FormattableElement(format="a") public static final ZonalElement<Meridiem> AM_PM_OF_DAY

      Element with the half day section relative to noon (ante meridiem or post meridiem).

      This element handles the value 24:00 in the same way as 00:00, hence does not make any difference between start and end of day. In detail the mapping from hours to meridiem values looks like following:

      Legend
      AM_PM_OF_DAYAMAM...AM PMPM...PMAM
      ISO-8601-WertT0T1...T11 T12T13...T23T24

      Example:

        import static net.time4j.PlainTime.AM_PM_OF_DAY;
      
        PlainTime time = PlainTime.of(12, 45, 20);
        System.out.println(time.get(AM_PM_OF_DAY));
        // Output: PM
       

      This element does not define a base unit.

    • CLOCK_HOUR_OF_AMPM

      @FormattableElement(format="h") public static final AdjustableElement<Integer,​PlainTime> CLOCK_HOUR_OF_AMPM

      Element with the hour of half day in the value range 1-12 (dial on an analogue watch).

      This element handles the value 24:00 in the same way as 00:00, hence does not make any difference between start and end of day. This is a limitation which preserves the compatibility with CLDR and the class java.text.SimpleDateFormat. In order to support the full hour range users can use the element HOUR_FROM_0_TO_24. In detail the mapping to full hours in range 0-24 looks like following:

      Legend
      CLOCK_HOUR_OF_AMPM121...11 121...1112
      Full-range hourT0T1...T11 T12T13...T23T24
    • CLOCK_HOUR_OF_DAY

      @FormattableElement(format="k") public static final AdjustableElement<Integer,​PlainTime> CLOCK_HOUR_OF_DAY

      Element with the hour in the value range 1-24 (analogue display).

      This element handles the value 24:00 in the same way as 00:00, hence does not make any difference between start and end of day. This is a limitation which preserves the compatibility with CLDR and the class java.text.SimpleDateFormat. In order to support the full hour range users can use the element HOUR_FROM_0_TO_24. In detail the mapping to full hours in range 0-24 looks like following:

      Legend
      CLOCK_HOUR_OF_DAY241...11 1213...2324
      Full-range hourT0T1...T11 T12T13...T23T24
    • DIGITAL_HOUR_OF_AMPM

      @FormattableElement(format="K") public static final ProportionalElement<Integer,​PlainTime> DIGITAL_HOUR_OF_AMPM

      Element with the digital hour of half day in the value range 0-11.

      This element handles the value 24:00 in the same way as 00:00, hence does not make any difference between start and end of day. This is a limitation which preserves the compatibility with CLDR and the class java.text.SimpleDateFormat. In order to support the full hour range users can use the element HOUR_FROM_0_TO_24. In detail the mapping to full hours in range 0-24 looks like following:

      Legend
      DIGITAL_HOUR_OF_AMPM01...11 01...110
      Full-range hourT0T1...T11 T12T13...T23T24
    • DIGITAL_HOUR_OF_DAY

      @FormattableElement(format="H") public static final ProportionalElement<Integer,​PlainTime> DIGITAL_HOUR_OF_DAY

      Element with the digital hour in the value range 0-23.

      This element handles the value 24:00 in the same way as 00:00, hence does not make any difference between start and end of day. This is a limitation which preserves the compatibility with CLDR and the class java.text.SimpleDateFormat. In order to support the full hour range users can use the element HOUR_FROM_0_TO_24. In detail the mapping to full hours in range 0-24 looks like following:

      Legend
      DIGITAL_HOUR_OF_DAY01...11 1213...230
      Full-range hourT0T1...T11 T12T13...T23T24
    • HOUR_FROM_0_TO_24

      public static final ProportionalElement<Integer,​PlainTime> HOUR_FROM_0_TO_24

      Element with the full hour of day in the value range 0-24.

      Given a context of PlainTime with full hours, the maximum is 24 and stands for the time 24:00 (midnight at end of day), else the maximum is 23 in every different context.

      Since:
      v3.35/4.30
      See Also:
      getHour()
    • MINUTE_OF_HOUR

      @FormattableElement(format="m") public static final ProportionalElement<Integer,​PlainTime> MINUTE_OF_HOUR

      Element with the minute of hour in the value range 0-59.

      See Also:
      getMinute()
    • MINUTE_OF_DAY

      public static final ProportionalElement<Integer,​PlainTime> MINUTE_OF_DAY

      Element with the minute of day in the value range 0-1440.

      Given a context of PlainTime with full minutes, the maximum is 1440 and stands for the time 24:00 (midnight at end of day), else the maximum is 1439 in every different context.

    • SECOND_OF_MINUTE

      @FormattableElement(format="s") public static final ProportionalElement<Integer,​PlainTime> SECOND_OF_MINUTE

      Element with the second of minute in the value range 0-59.

      This element does not know any leapseconds in a local context and refers to a normal analogue clock. If this element is used in UTC-context (Moment) however then the value range is 0-58/59/60 instead.

      See Also:
      getSecond()
    • SECOND_OF_DAY

      public static final ProportionalElement<Integer,​PlainTime> SECOND_OF_DAY

      Element with the second of day in the value range 0-86400.

      Given a context of PlainTime with full seconds, the maximum is 86400 and stands for the time 24:00 (midnight at end of day), else the maximum is 86399 in every different context. Leapseconds are never counted.

    • MILLI_OF_SECOND

      public static final ProportionalElement<Integer,​PlainTime> MILLI_OF_SECOND

      Element with the millisecond in the value range 0-999.

    • MICRO_OF_SECOND

      public static final ProportionalElement<Integer,​PlainTime> MICRO_OF_SECOND

      Element with the microsecond in the value range 0-999999.

    • NANO_OF_SECOND

      @FormattableElement(format="S") public static final ProportionalElement<Integer,​PlainTime> NANO_OF_SECOND

      Element with the nanosecond in the value range 0-999999999.

    • MILLI_OF_DAY

      @FormattableElement(format="A") public static final ProportionalElement<Integer,​PlainTime> MILLI_OF_DAY

      Element with the day time in milliseconds in the value range 0-86400000.

      Given a context of PlainTime with full milliseconds, the maximum is 86400000 and stands for the time 24:00 (midnight at end of day), else the maximum is 86399999 in every different context. Leapseconds are never counted.

    • MICRO_OF_DAY

      public static final ProportionalElement<Long,​PlainTime> MICRO_OF_DAY

      Element with the day time in microseconds in the value range 0-86400000000.

      Given a context of PlainTime with full microseconds, the maximum is 86400000000 and stands for the time 24:00 (midnight at end of day), else the maximum is 86399999999 in every different context. Leapseconds are never counted.

    • NANO_OF_DAY

      public static final ProportionalElement<Long,​PlainTime> NANO_OF_DAY

      Element with the day time in nanoseconds in the value range 0-86400000000000.

      Given any context of PlainTime, the maximum is always 86400000000000 and stands for the time 24:00 (midnight at end of day), else the maximum is 86399999999999 in every different context. Leapseconds are never counted.

      Example:

        import static net.time4j.ClockUnit.HOURS;
        import static net.time4j.PlainTime.NANO_OF_DAY;
      
        PlainTime time =
            PlainTime.midnightAtStartOfDay().plus(6, HOURS); // T06:00
        System.out.println(
            time.get(NANO_OF_DAY.ratio())
                .multiply(BigDecimal.ofHour(100)).stripTrailingZeros()
            + "% of day are over.");
        // Output: 25% of day are over.
       
    • DECIMAL_HOUR

      public static final ZonalElement<BigDecimal> DECIMAL_HOUR

      Decimal hour in the value range 0.0 inclusive until 24.0 exclusive (inclusive in PlainTime).

      This element does not define any base unit.

    • DECIMAL_MINUTE

      public static final ZonalElement<BigDecimal> DECIMAL_MINUTE

      Decimal minute in the value range 0.0 inclusive until 60.0 exclusive.

      This element does not define any base unit.

    • DECIMAL_SECOND

      public static final ZonalElement<BigDecimal> DECIMAL_SECOND

      Decimal second in the value range 0.0 inclusive until 60.0 exclusive.

      This element does not define any base unit.

    • PRECISION

      public static final ChronoElement<ClockUnit> PRECISION

      Defines the precision as the smallest non-zero time element and truncates time parts of higher precision if necessary.

      Setting higher precisions than available is without any effect. But setting lower precisions can truncate data however. Examples:

        // reading of precision -------------------------------------
        PlainTime time = PlainTime.of(12, 26, 52, 987654000);
        System.out.println(time.get(PRECISION)); // Output: MICROS
      
        // setting of precision -------------------------------------
        PlainTime time = PlainTime.of(12, 26, 52, 987654000);
        System.out.println(time.with(PRECISION, ClockUnit.MILLIS));
        // Output: T12:26:52,987
       

      This element does not define any base unit.

  • Method Details

    • getHour

      public int getHour()
      Description copied from interface: WallTime

      Yields the hour of day.

      Specified by:
      getHour in interface WallTime
      Returns:
      hour in range 0 - 24 (the value 24 is only allowed if minute and second have the value 0)
    • getMinute

      public int getMinute()
      Description copied from interface: WallTime

      Yields the minute of hour.

      Specified by:
      getMinute in interface WallTime
      Returns:
      minute in range 0 - 59
    • getSecond

      public int getSecond()
      Description copied from interface: WallTime

      Yields the second of minute.

      Given this context and the fact that this interface describes an analogue clock without UTC reference, the special leapsecond value 60 cannot be supported.

      Specified by:
      getSecond in interface WallTime
      Returns:
      second in range 0 - 59
    • getNanosecond

      public int getNanosecond()
      Description copied from interface: WallTime

      Yields the nanosecond.

      Implementations which are not capable of nanosecond precision will just yield 0 or another suitable rounded value.

      Specified by:
      getNanosecond in interface WallTime
      Returns:
      nanosecond in range 0 - 999,999,999
    • midnightAtStartOfDay

      public static PlainTime midnightAtStartOfDay()

      Yields midnight at the start of the day.

      Returns:
      midnight at the start of day T00:00
      See Also:
      midnightAtEndOfDay()
    • midnightAtEndOfDay

      public static PlainTime midnightAtEndOfDay()

      Yields midnight at the end of the day, that is midnight at the start of the following day.

      Returns:
      midnight at the end of day T24:00
      See Also:
      midnightAtStartOfDay()
    • of

      public static PlainTime of(int hour)

      Creates a wall time as full hour.

      Parameters:
      hour - iso-hour of day in the range 0-24
      Returns:
      cached full hour
      Throws:
      IllegalArgumentException - if given hour is out of range
    • of

      public static PlainTime of(int hour, int minute)

      Creates a wall time with hour and minute.

      Parameters:
      hour - hour of day in the range 0-23 or 24 if the given minute equals to 0
      minute - minute in the range 0-59
      Returns:
      new or cached wall time
      Throws:
      IllegalArgumentException - if any argument is out of range
    • of

      public static PlainTime of(int hour, int minute, int second)

      Creates a wall time with hour, minute and second.

      Parameters:
      hour - hour in the range 0-23 or 24 if the other arguments are equal to 0
      minute - minute in the range 0-59
      second - second in the range 0-59
      Returns:
      new or cached wall time
      Throws:
      IllegalArgumentException - if any argument is out of range
    • of

      public static PlainTime of(int hour, int minute, int second, int nanosecond)

      Creates a wall time with hour, minute, second and nanosecond.

      Parameters:
      hour - hour in the range 0-23 or 24 if the other argumenta equal to 0
      minute - minute in the range 0-59
      second - second in the range 0-59
      nanosecond - nanosecond in the range 0-999,999,999
      Returns:
      new or cached wall time
      Throws:
      IllegalArgumentException - if any argument is out of range
      See Also:
      of(int), of(int, int), of(int, int, int), NANO_OF_SECOND
    • of

      public static PlainTime of(BigDecimal decimal)

      Creates a wall time by given decimal hour.

      Parameters:
      decimal - decimal hour of day in the range [0.0-24.0]
      Returns:
      new or cached wall time
      Throws:
      IllegalArgumentException - if the argument is out of range
      See Also:
      DECIMAL_HOUR
    • nowInSystemTime

      public static PlainTime nowInSystemTime()

      Obtains the current clock time in system time.

      Convenient short-cut for: SystemClock.inLocalView().now().toTime().

      Returns:
      current wall time (without zone) in system time zone using the system clock
      Since:
      3.23/4.19
      See Also:
      SystemClock.inLocalView(), ZonalClock.now()
    • from

      public static PlainTime from(WallTime time)

      Common conversion method.

      Parameters:
      time - ISO-time
      Returns:
      PlainTime
    • from

      public static PlainTime from(LocalTime time)

      Short cut for TemporalType.LOCAL_TIME.translate(time).

      Parameters:
      time - Threeten-equivalent of this instance
      Returns:
      PlainTime
      Since:
      4.0
      See Also:
      TemporalType.LOCAL_TIME
    • plus

      public PlainTime plus(long amount, ClockUnit unit)

      Adds given amount in units to this clock time and yields the result of addition.

      Covers the most important units and is overloaded for performance reasons.

      Parameters:
      amount - the amount of units to be added to this clock time (maybe negative)
      unit - the unit to be used in addition
      Returns:
      result of addition as changed copy while this instance remains unaffected
      Throws:
      ArithmeticException - in case of numerical overflow
      Since:
      4.19
      See Also:
      plus(long, IsoTimeUnit)
    • minus

      public PlainTime minus(long amount, ClockUnit unit)

      Subtracts given amount in units from this clock time and yields the result of subtraction.

      Covers the most important units and is overloaded for performance reasons.

      Parameters:
      amount - the amount of units to be subtracted from this clock time (maybe negative)
      unit - the unit to be used in subtraction
      Returns:
      result of subtraction as changed copy while this instance remains unaffected
      Throws:
      ArithmeticException - in case of numerical overflow
      Since:
      4.19
      See Also:
      minus(long, IsoTimeUnit)
    • roll

      public DayCycles roll(long amount, ClockUnit unit)

      Rolls this time by the given duration (as amount and unit) and also counts possible day overflow.

      Parameters:
      amount - amount to be added (maybe negative)
      unit - time unit
      Returns:
      result of rolling including possible day overflow
      See Also:
      plus(long, IsoTimeUnit)
    • print

      public String print(TemporalFormatter<PlainTime> printer)

      Creates a formatted output of this instance.

      Parameters:
      printer - helps to format this instance
      Returns:
      formatted string
      Since:
      5.0
    • parse

      public static PlainTime parse(String text, TemporalFormatter<PlainTime> parser)

      Parses given text to an instance of this class.

      Parameters:
      text - text to be parsed
      parser - helps to parse given text
      Returns:
      parsed result
      Throws:
      IndexOutOfBoundsException - if the text is empty
      ChronoException - if the text is not parseable
      Since:
      5.0
    • equals

      public boolean equals(Object obj)

      Compares the full state, that is hour, minute, second and nanosecond of this instance and given argument.

      Specified by:
      equals in class TimePoint<IsoTimeUnit,​PlainTime>
      See Also:
      TimePoint.compareTo(TimePoint)
    • hashCode

      public int hashCode()
      Description copied from class: TimePoint

      Subclasses must redefine this method corresponding to the behaviour of equals().

      Specified by:
      hashCode in class TimePoint<IsoTimeUnit,​PlainTime>
    • isBefore

      public boolean isBefore(PlainTime time)
      Description copied from interface: Temporal

      Queries if this object is before given object on a timeline.

      Specified by:
      isBefore in interface Temporal<PlainTime>
      Parameters:
      time - object this instance is compared to
      Returns:
      true if this instance is temporally before temporal else false
    • isAfter

      public boolean isAfter(PlainTime time)
      Description copied from interface: Temporal

      Queries if this object is after given object on a timeline.

      Specified by:
      isAfter in interface Temporal<PlainTime>
      Parameters:
      time - object this instance is compared to
      Returns:
      true if this instance is temporally after temporal else false
    • isSimultaneous

      public boolean isSimultaneous(PlainTime time)
      Description copied from interface: Temporal

      Queries if this object and given object have the same position on the time axis.

      Is equivalent to !isAfter(temporal) && !isBefore(temporal). This method differs from the Object-method equals() such that first the comparison type must be a temporal one and second that only temporal-only state will be considered.

      Specified by:
      isSimultaneous in interface Temporal<PlainTime>
      Parameters:
      time - object this instance is compared to
      Returns:
      true if this instance is temporally equal to temporal else false
    • isMidnight

      public boolean isMidnight()

      Is this instance at midnight, either at start or at end of day?

      Returns:
      boolean
    • compareTo

      public int compareTo(PlainTime time)

      Defines a natural order which is solely based on the timeline order.

      The natural order is consistent with equals().

      Specified by:
      compareTo in interface Comparable<PlainTime>
      Specified by:
      compareTo in class TimePoint<IsoTimeUnit,​PlainTime>
      See Also:
      isBefore(PlainTime), isAfter(PlainTime)
    • toString

      public String toString()

      Dependent on the precision of this instance, this method yields a canonical representation in one of following formats (CLDR-syntax):

      • 'T'HH
      • 'T'HH:mm
      • 'T'HH:mm:ss
      • 'T'HH:mm:ss,SSS
      • 'T'HH:mm:ss,SSSSSS
      • 'T'HH:mm:ss,SSSSSSSSS

      The fraction part will be preceded by a comma as recommended by ISO unless the system property "net.time4j.format.iso.decimal.dot" was set to "true".

      Specified by:
      toString in interface WallTime
      Specified by:
      toString in class TimePoint<IsoTimeUnit,​PlainTime>
      Returns:
      canonical ISO-8601-formatted string
    • toTemporalAccessor

      public LocalTime toTemporalAccessor()
      Description copied from interface: ThreetenAdapter

      Converts this object to a TemporalAccessor.

      Any implementation is required to return a new object with a different concrete type, not this instance.

      Specified by:
      toTemporalAccessor in interface ThreetenAdapter
      Returns:
      converted Threeten-object (always as new object)
    • getFormatPattern

      public String getFormatPattern(FormatStyle style, Locale locale)
      Description copied from interface: LocalizedPatternSupport

      Defines a CLDR-compatible localized format pattern suitable for printing.

      The default implementation delegates to the underlying chronology.

      Specified by:
      getFormatPattern in interface LocalizedPatternSupport
      Parameters:
      style - format style
      locale - language and country setting
      Returns:
      localized format pattern
    • axis

      public static TimeAxis<IsoTimeUnit,​PlainTime> axis()

      Provides a static access to the associated time axis respective chronology which contains the chronological rules.

      Returns:
      chronological system as time axis (never null)
    • threeten

      public static Chronology<LocalTime> threeten()

      Obtains a bridge chronology for the type java.time.LocalTime.

      Returns:
      rule engine adapted for the type java.time.LocalTime
      Since:
      5.0
      See Also:
      axis()