Class TimeUnit

All Implemented Interfaces:
Serializable, Cloneable

public class TimeUnit
extends AbsoluteLinearUnit<TimeUnit,​DurationUnit>
Standard absolute time units. Note that when the offset of a stored absolute Time becomes large, precision of a float or double might not be enough for the required resolution of a Time. A float has around 7 significant digits (23 bit mantissa), whereas a double has around 16 significant digits (52 bit mantissa). This means that when we need to have a float time that is precise to microseconds, the Time value should not go above 2^22 = 4.0E6. This is not enough to store Epoch values! So feeding System.TimeInMillis() to a FloatTime with TimeUnit.BASE as its unit is not having the required precision. For a (double) Time with TimeUnit.BASE as its unit, the largest value where the ms precision is reached is 2^51 = 2.3E15, which is around 71000 years. This is sufficient to store a date on an Epoch level precise to a ms.

Copyright (c) 2015-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See DJUNITS License.

Author:
Alexander Verbraeck
See Also:
Serialized Form
  • Field Details

    • BASE

      public static final Quantity<TimeUnit> BASE
      The base, with "m2" as the SI signature.
    • BASE_SECOND

      public static final TimeUnit BASE_SECOND
      The base unit for time with an artifical "zero" point with a calculation in seconds. Note that when the offset becomes large, precision of a float or double might not be enough for the required resolution of a Time. A float has around 7 significant digits (23 bit mantissa), whereas a double has around 16 significant digits (52 bit mantissa). This means that when we need to have a float time that is precise to microseconds, the Time value should not go above 2^22 = 4.0E6. This is not enough to store Epoch values! So feeding System.TimeInMillis() to a FloatTime with TimeUnit.BASE as its unit is not having the required precision. For a (double) Time with TimeUnit.BASE as its unit, the largest value where the ms precision is reached is 2^51 = 2.3E15, which is around 71000 years. This is sufficient to store a date on an Epoch level precise to a ms.
    • DEFAULT

      public static final TimeUnit DEFAULT
      The default unit for time is BASE_SECOND.
    • BASE_MICROSECOND

      public static final TimeUnit BASE_MICROSECOND
      The base unit for time with an artificial "zero" point with a calculation in microseconds.
    • BASE_MILLISECOND

      public static final TimeUnit BASE_MILLISECOND
      The base unit for time with an artificial "zero" point with a calculation in milliseconds.
    • BASE_MINUTE

      public static final TimeUnit BASE_MINUTE
      The base unit for time with an artificial "zero" point with a calculation in minutes.
    • BASE_HOUR

      public static final TimeUnit BASE_HOUR
      The base unit for time with an artificial "zero" point with a calculation in hours.
    • BASE_DAY

      public static final TimeUnit BASE_DAY
      The base unit for time with an artificial "zero" point with a calculation in days.
    • BASE_WEEK

      public static final TimeUnit BASE_WEEK
      The base unit for time with an artificial "zero" point with a calculation in weeks.
    • EPOCH_SECOND

      public static final TimeUnit EPOCH_SECOND
      The POSIX and Gregorian Epoch: January 1, 1970 at 00:00 UTC with a calculation in seconds. The base should be taken in such a way that a resolution of a millisecond is still 'visible' on a date in, say, 2020. When 1-1-1970 is used as the origin, 1-1-2020 has a value of 1,577,836,800,000 milliseconds = 1.6E12 ms. If we want to be precise on the ms level, we need 12 significant digits. A float has around 7 significant digits (23 bit mantissa), whereas a double has around 16 significant digits (52 bit mantissa). This means that a float time with an offset of 1-1-1970 is at best precise to a minute level. A double time is precise to microseconds. Therefore, avoid using float times that use the EPOCH.
    • EPOCH_MICROSECOND

      public static final TimeUnit EPOCH_MICROSECOND
      The POSIX and Gregorian Epoch: January 1, 1970 at 00:00 UTC with a calculation in microseconds.
    • EPOCH_MILLISECOND

      public static final TimeUnit EPOCH_MILLISECOND
      The POSIX and Gregorian Epoch: January 1, 1970 at 00:00 UTC with a calculation in milliseconds.
    • EPOCH_MINUTE

      public static final TimeUnit EPOCH_MINUTE
      The POSIX and Gregorian Epoch: January 1, 1970 at 00:00 UTC with a calculation in minutes.
    • EPOCH_HOUR

      public static final TimeUnit EPOCH_HOUR
      The POSIX and Gregorian Epoch: January 1, 1970 at 00:00 UTC with a calculation in hours.
    • EPOCH_DAY

      public static final TimeUnit EPOCH_DAY
      The POSIX and Gregorian Epoch: January 1, 1970 at 00:00 UTC with a calculation in days.
    • EPOCH_WEEK

      public static final TimeUnit EPOCH_WEEK
      The POSIX and Gregorian Epoch: January 1, 1970 at 00:00 UTC with a calculation in weeks.
    • EPOCH_YEAR1_SECOND

      public static final TimeUnit EPOCH_YEAR1_SECOND
      The Epoch with 0001-01-01 AD at 00:00 as the origin with a calculation in seconds. When 1-1-0001 is used as the origin, 1-1-2020 has a value of around 6.4E13 ms. If we want to be precise on the ms level, we need 13 significant digits. A float has around 7 significant digits (23 bit mantissa), whereas a double has around 16 significant digits (52 bit mantissa). This means that a float time with an offset of 1-1-0001 is at best precise to an hour level. A double time is precise to microseconds. Therefore, avoid using float times that use the EPOCH_YEAR1_SECOND.
    • EPOCH_J2000_SECOND

      public static final TimeUnit EPOCH_J2000_SECOND
      The Epoch with J2000.0 as the origin, which is The Gregorian date January 1, 2000 at 12:00 GMT (noon) with a calculation in seconds. When 1-1-2000 is used as the origin, 1-1-2020 has a value of around 6.3E11 ms. If we want to be precise on the ms level, we need 11 significant digits. A float has around 7 significant digits (23 bit mantissa), whereas a double has around 16 significant digits (52 bit mantissa). This means that a float time with an offset of 1-1-2000 is at best precise to a minute level. A double time is precise to fractions of microseconds. Therefore, avoid using float times that use the EPOCH_J2000_SECOND.
  • Constructor Details