Enum Class DurationUnit

java.lang.Object
java.lang.Enum<DurationUnit>
com.norconex.commons.lang.time.DurationUnit
All Implemented Interfaces:
Serializable, Comparable<DurationUnit>, Constable

public enum DurationUnit extends Enum<DurationUnit>
Duration unit. These units are best used with a general estimation is acceptable. The quantities for each units are fixed, and never change according to a specific era or moment in time. For instance a year is a fixed average of approximately 365.2425 days.
Since:
2.0.0
  • Enum Constant Details

  • Method Details

    • values

      public static DurationUnit[] 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 DurationUnit 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
    • toTemporalUnit

      public ChronoUnit toTemporalUnit()
    • toDuration

      public Duration toDuration()
    • toMilliseconds

      public long toMilliseconds()
    • toMilliseconds

      public long toMilliseconds(long amount)
    • toSeconds

      public long toSeconds()
    • toSeconds

      public long toSeconds(long amount)
    • toMinutes

      public long toMinutes()
    • toMinutes

      public long toMinutes(long amount)
    • toHours

      public long toHours()
    • toHours

      public long toHours(long amount)
    • toDays

      public long toDays()
    • toDays

      public long toDays(long amount)
    • toWeeks

      public long toWeeks()
    • toWeeks

      public long toWeeks(long amount)
    • toMonths

      public long toMonths()
    • toMonths

      public long toMonths(long amount)
    • toYears

      public long toYears()
    • toYears

      public long toYears(long amount)
    • toUnit

      public long toUnit(DurationUnit targetUnit, long amount)
    • from

      public static DurationUnit from(Duration duration)
      Gets the largest unit fitting in the provided duration. If the duration is null, zero, or less, null is returned.
      Parameters:
      duration - duration in milliseconds
      Returns:
      duration unit
    • from

      public static DurationUnit from(long duration)
      Gets the largest unit fitting in the provided duration. If the duration is zero or less, null is returned.
      Parameters:
      duration - duration in milliseconds
      Returns:
      duration unit
    • from

      public static DurationUnit from(String unit)
      Gets the DurationUnit matching the provided string (case insensitive) or null if there are no units matching.
      Parameters:
      unit - unit name
      Returns:
      duration unit
    • from

      public static DurationUnit from(TemporalUnit temporalUnit)
    • reverseValues

      public static DurationUnit[] reverseValues()
      Returns all units from the highest (year), to the smallest (milliseconds).
      Returns:
      duration units
    • reverseOrdinal

      public int reverseOrdinal()
      Gets ordinal value in reverse order.
      Returns:
      ordinal value