Package net.time4j

Enum Class ClockUnit

All Implemented Interfaces:
Serializable, Comparable<ClockUnit>, java.lang.constant.Constable, ChronoUnit, IsoTimeUnit, IsoUnit

public enum ClockUnit extends Enum<ClockUnit> implements IsoTimeUnit

Represents the most common time units on an ISO-8601-conforming analogue clock counting the scale ticks.

Author:
Meno Hochschild
  • 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
    Time unit "hours" (symbol H)
    Time unit "microseconds" (symbol 6)
    Time unit "milliseconds" (symbol 3)
    Time unit "minutes" (symbol M)
    Time unit "nanoseconds" (symbol 9)
    Time unit "seconds" (symbol S) according to the position of the second pointer on an analogue clock.
  • Method Summary

    Modifier and Type
    Method
    Description
    <T extends TimePoint<? super ClockUnit,​ T>>
    long
    between​(T start, T end)
    Calculates the temporal distance between given wall times in this unit.
    long
    convert​(long sourceDuration, ClockUnit sourceUnit)
    Converts the given duration to a temporal amount measured in this unit.
    long
    convert​(TimeSpan<? extends ClockUnit> duration)
    Converts the given duration to an amount in this unit and performs any necessary truncation if needed.
    boolean
    A wall time unit is never calendrical.
    Yields a normalizer which converts a given duration in another duration with only this clock unit.
    Yields a normalizer which converts a given duration in another normalized duration with smaller units truncated and this unit rounded.
    Yields a normalizer which converts a given duration in another duration with smaller units truncated.
    static ClockUnit
    valueOf​(String name)
    Returns the enum constant of this class with the specified name.
    static ClockUnit[]
    Returns an array containing the constants of this enum class, in the order they are declared.

    Methods inherited from class java.lang.Enum

    compareTo, describeConstable, equals, getDeclaringClass, hashCode, name, ordinal, toString, valueOf

    Methods inherited from class java.lang.Object

    getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface net.time4j.engine.ChronoUnit

    getLength

    Methods inherited from interface net.time4j.IsoUnit

    getSymbol
  • Enum Constant Details

    • HOURS

      public static final ClockUnit HOURS
      Time unit "hours" (symbol H)
    • MINUTES

      public static final ClockUnit MINUTES
      Time unit "minutes" (symbol M)
    • SECONDS

      public static final ClockUnit SECONDS

      Time unit "seconds" (symbol S) according to the position of the second pointer on an analogue clock.

      This unit is NOT the SI-second.

      See Also:
      SI
    • MILLIS

      public static final ClockUnit MILLIS
      Time unit "milliseconds" (symbol 3)
    • MICROS

      public static final ClockUnit MICROS
      Time unit "microseconds" (symbol 6)
    • NANOS

      public static final ClockUnit NANOS
      Time unit "nanoseconds" (symbol 9)
  • Method Details

    • values

      public static ClockUnit[] 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 ClockUnit 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
    • between

      public <T extends TimePoint<? super ClockUnit,​ T>> long between(T start, T end)

      Calculates the temporal distance between given wall times in this unit.

      Type Parameters:
      T - generic type of time point
      Parameters:
      start - starting time
      end - ending time
      Returns:
      duration as count of this unit
    • convert

      public long convert(long sourceDuration, ClockUnit sourceUnit)

      Converts the given duration to a temporal amount measured in this unit.

      Conversions from more precise to less precise units are usually associated with a loss of information. For example the conversion of 999 milliseconds results to 0 seconds. In reverse, the conversion of less precise to more precise units can result in a numerical overflow.

      Example: In order to convert 44 minutes to milliseconds, the expression ClockUnit.MILLIS.convert(44L, ClockUnit.MINUTES) is applied. Note: If hours or minutes are to be converted then UTC-leapseconds will be ignored that is a minute has here always 60 seconds.

      Parameters:
      sourceDuration - amount of duration to be converted
      sourceUnit - time unit of duration to be converted
      Returns:
      converted duration expressed in this unit
      Throws:
      ArithmeticException - in case of long overflow
    • convert

      public long convert(TimeSpan<? extends ClockUnit> duration)

      Converts the given duration to an amount in this unit and performs any necessary truncation if needed.

      Parameters:
      duration - temporal amount in clock units to be converted
      Returns:
      count of this unit representing given duration
      Since:
      1.2
    • only

      public Normalizer<ClockUnit> only()

      Yields a normalizer which converts a given duration in another duration with only this clock unit.

      Returns:
      normalizer
      Since:
      1.2
      See Also:
      convert(TimeSpan)
    • truncated

      public Normalizer<ClockUnit> truncated()

      Yields a normalizer which converts a given duration in another duration with smaller units truncated.

      Returns:
      normalizer
      Since:
      3.0
      See Also:
      Duration.truncatedTo(IsoUnit)
    • rounded

      public Normalizer<ClockUnit> rounded()

      Yields a normalizer which converts a given duration in another normalized duration with smaller units truncated and this unit rounded.

      This normalizer is a combination of Duration.STD_CLOCK_PERIOD, truncated() and a special half-up rounding. Example:

        Duration<ClockUnit> timePeriod = Duration.ofClockUnits(4, 55, 90);
        System.out.println(timePeriod.with(ClockUnit.MINUTES.rounded()));
        // output: P4H57M
       
      Returns:
      normalizer
      Since:
      3.0
      See Also:
      Duration.STD_CLOCK_PERIOD
    • isCalendrical

      public boolean isCalendrical()

      A wall time unit is never calendrical.

      Specified by:
      isCalendrical in interface ChronoUnit
      Returns:
      false