Enum Class TimeUnit

java.lang.Object
java.lang.Enum<TimeUnit>
com.thewinterframework.utils.TimeUnit
All Implemented Interfaces:
Serializable, Comparable<TimeUnit>, Constable, TemporalUnit

public enum TimeUnit extends Enum<TimeUnit> implements TemporalUnit
A standard set of date periods units.

This set of units provide unit-based access to manipulate a date, time or date-time. The standard set of units can be extended by implementing TemporalUnit.

These units are intended to be applicable in multiple calendar systems. For example, most non-ISO calendar systems define units of years, months and days, just with slightly different rules. The documentation of each unit explains how it operates.

Since:
1.00
  • 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
    Unit that represents the concept of a century.
    Unit that represents the concept of a day.
    Unit that represents the concept of a decade.
    Unit that represents the concept of an era.
    Artificial unit that represents the concept of forever.
    Unit that represents the concept of half a day, as used in AM/PM.
    Unit that represents the concept of an hour.
    Unit that represents the concept of a microsecond.
    Unit that represents the concept of a millennium.
    Unit that represents the concept of a millisecond.
    Unit that represents the concept of a minute.
    Unit that represents the concept of a month.
    Unit that represents the concept of a nanosecond, the smallest supported unit of time.
    Unit that represents the concept of a second.
    Unit that represents the concept of a tick, the time unit used by Minecraft.
    Unit that represents the concept of a week.
    Unit that represents the concept of a year.
  • Method Summary

    Modifier and Type
    Method
    Description
    <R extends Temporal>
    R
    addTo(R temporal, long amount)
     
    long
    between(Temporal temporal1Inclusive, Temporal temporal2Exclusive)
     
    Gets the estimated duration of this unit in the ISO calendar system.
    boolean
    Checks if this unit is a date unit.
    boolean
    Checks if the duration of the unit is an estimate.
    boolean
     
    boolean
    Checks if this unit is a time unit.
     
    long
    toTicks(long amount)
     
    static TimeUnit
    Returns the enum constant of this class with the specified name.
    static TimeUnit[]
    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

    • TICKS

      public static final TimeUnit TICKS
      Unit that represents the concept of a tick, the time unit used by Minecraft.
    • NANOS

      public static final TimeUnit NANOS
      Unit that represents the concept of a nanosecond, the smallest supported unit of time. For the ISO calendar system, it is equal to the 1,000,000,000th part of the second unit.
    • MICROS

      public static final TimeUnit MICROS
      Unit that represents the concept of a microsecond. For the ISO calendar system, it is equal to the 1,000,000th part of the second unit.
    • MILLIS

      public static final TimeUnit MILLIS
      Unit that represents the concept of a millisecond. For the ISO calendar system, it is equal to the 1000th part of the second unit.
    • SECONDS

      public static final TimeUnit SECONDS
      Unit that represents the concept of a second. For the ISO calendar system, it is equal to the second in the SI system of units, except around a leap-second.
    • MINUTES

      public static final TimeUnit MINUTES
      Unit that represents the concept of a minute. For the ISO calendar system, it is equal to 60 seconds.
    • HOURS

      public static final TimeUnit HOURS
      Unit that represents the concept of an hour. For the ISO calendar system, it is equal to 60 minutes.
    • HALF_DAYS

      public static final TimeUnit HALF_DAYS
      Unit that represents the concept of half a day, as used in AM/PM. For the ISO calendar system, it is equal to 12 hours.
    • DAYS

      public static final TimeUnit DAYS
      Unit that represents the concept of a day. For the ISO calendar system, it is the standard day from midnight to midnight. The estimated duration of a day is 24 Hours.

      When used with other calendar systems it must correspond to the day defined by the rising and setting of the Sun on Earth. It is not required that days begin at midnight - when converting between calendar systems, the date should be equivalent at midday.

    • WEEKS

      public static final TimeUnit WEEKS
      Unit that represents the concept of a week. For the ISO calendar system, it is equal to 7 days.

      When used with other calendar systems it must correspond to an integral number of days.

    • MONTHS

      public static final TimeUnit MONTHS
      Unit that represents the concept of a month. For the ISO calendar system, the length of the month varies by month-of-year. The estimated duration of a month is one twelfth of 365.2425 Days.

      When used with other calendar systems it must correspond to an integral number of days.

    • YEARS

      public static final TimeUnit YEARS
      Unit that represents the concept of a year. For the ISO calendar system, it is equal to 12 months. The estimated duration of a year is 365.2425 Days.

      When used with other calendar systems it must correspond to an integral number of days or months roughly equal to a year defined by the passage of the Earth around the Sun.

    • DECADES

      public static final TimeUnit DECADES
      Unit that represents the concept of a decade. For the ISO calendar system, it is equal to 10 years.

      When used with other calendar systems it must correspond to an integral number of days and is normally an integral number of years.

    • CENTURIES

      public static final TimeUnit CENTURIES
      Unit that represents the concept of a century. For the ISO calendar system, it is equal to 100 years.

      When used with other calendar systems it must correspond to an integral number of days and is normally an integral number of years.

    • MILLENNIA

      public static final TimeUnit MILLENNIA
      Unit that represents the concept of a millennium. For the ISO calendar system, it is equal to 1000 years.

      When used with other calendar systems it must correspond to an integral number of days and is normally an integral number of years.

    • ERAS

      public static final TimeUnit ERAS
      Unit that represents the concept of an era. The ISO calendar system doesn't have eras thus it is impossible to add an era to a date or date-time. The estimated duration of the era is artificially defined as 1,000,000,000 Years.

      When used with other calendar systems there are no restrictions on the unit.

    • FOREVER

      public static final TimeUnit FOREVER
      Artificial unit that represents the concept of forever. This is primarily used with TemporalField to represent unbounded fields such as the year or era. The estimated duration of this unit is artificially defined as the largest duration supported by Duration.
  • Method Details

    • values

      public static TimeUnit[] 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 TimeUnit 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
    • getDuration

      public Duration getDuration()
      Gets the estimated duration of this unit in the ISO calendar system.

      All the units in this class have an estimated duration. Days vary due to daylight saving time, while months have different lengths.

      Specified by:
      getDuration in interface TemporalUnit
      Returns:
      the estimated duration of this unit, not null
    • toTicks

      public long toTicks(long amount)
    • isDurationEstimated

      public boolean isDurationEstimated()
      Checks if the duration of the unit is an estimate.

      All time units in this class are considered to be accurate, while all date units in this class are considered to be estimated.

      This definition ignores leap seconds, but considers that Days vary due to daylight saving time and months have different lengths.

      Specified by:
      isDurationEstimated in interface TemporalUnit
      Returns:
      true if the duration is estimated, false if accurate
    • isDateBased

      public boolean isDateBased()
      Checks if this unit is a date unit.

      All units from days to eras inclusive are date-based. Time-based units and FOREVER return false.

      Specified by:
      isDateBased in interface TemporalUnit
      Returns:
      true if a date unit, false if a time unit
    • isTimeBased

      public boolean isTimeBased()
      Checks if this unit is a time unit.

      All units from nanos to half-days inclusive are time-based. Date-based units and FOREVER return false.

      Specified by:
      isTimeBased in interface TemporalUnit
      Returns:
      true if a time unit, false if a date unit
    • isSupportedBy

      public boolean isSupportedBy(Temporal temporal)
      Specified by:
      isSupportedBy in interface TemporalUnit
    • addTo

      public <R extends Temporal> R addTo(R temporal, long amount)
      Specified by:
      addTo in interface TemporalUnit
    • between

      public long between(Temporal temporal1Inclusive, Temporal temporal2Exclusive)
      Specified by:
      between in interface TemporalUnit
    • toString

      public String toString()
      Specified by:
      toString in interface TemporalUnit
      Overrides:
      toString in class Enum<TimeUnit>