Class TimeStampPosixMicrosInt64

  • All Implemented Interfaces:
    Serializable, Comparable<TimeStamp>

    public class TimeStampPosixMicrosInt64
    extends TimeStamp
    implements Serializable
    A TimeStamp implementation that stores the number of microseconds since the epoch (1970-01-01 00:00:00 UTC) as a long.

    Advantages of this implementation:

    • More precise than milliseconds, while still having a a large enough max range (300,000 years) for any imaginable application.
    • Storing an integral representation of a time allows reversible arithmetic and sensible comparison.

    Disadvantanges of this implementation:

    • Many existing systems and libraries (java.lang.Date, MySQL) store time in POSIX milliseconds. Interoperation between such libraries and this class introduces small conversion costs, and more significantly, the possibility of rounding error.
    • This class's methods are subject to arithmetic overflow. However, this does happen until the distance from the epoch reaches about 300,000 years, so we make no effort to detect overflow.
    Author:
    hogye
    See Also:
    Serialized Form
    • Method Detail

      • add

        public TimeStampPosixMicrosInt64 add​(double duration)
        Description copied from class: TimeStamp
        Creates a new TimeStamp instance offset from this timestamp by the given amount. The returned instance may or may not be of the same dynamic type as this instance.
        Specified by:
        add in class TimeStamp
        Parameters:
        duration - the amount of time to add in system-units
      • subtract

        public TimeStampPosixMicrosInt64 subtract​(double duration)
        Description copied from class: TimeStamp
        Creates a new TimeStamp instance offset from this timestamp by the given amount. The returned instance may or may not be of the same dynamic type as this instance.
        Specified by:
        subtract in class TimeStamp
        Parameters:
        duration - the amount of time to subtract in system-units
      • durationBefore

        public double durationBefore​(TimeStamp o)
        Description copied from class: TimeStamp
        Determines how long before the given timestamp this timestamp is. That is: durationBefore = other - this In the base-class implementation, arithmetic is done with BigDecimal. This is quite effective at minimizing rounding error, but may be slow compared to primitive arithmetic.
        Overrides:
        durationBefore in class TimeStamp
        Returns:
        the difference, in system-units
      • durationAfter

        public double durationAfter​(TimeStamp o)
        Description copied from class: TimeStamp
        Determines how long after the given timestamp this timestamp is. That is: durationAfter = this - other In the base-class implementation, arithmetic is done with BigDecimal. This is quite effective at minimizing rounding error, but may be slow compared to primitive arithmetic.
        Overrides:
        durationAfter in class TimeStamp
        Returns:
        the difference, in system-units
      • toPosixSeconds

        public double toPosixSeconds()
        Description copied from class: TimeStamp
        Converts this TimeStamp to posix seconds.
        Specified by:
        toPosixSeconds in class TimeStamp
        Returns:
        seconds since the epoch
      • toPosixMillis

        public long toPosixMillis()
        Description copied from class: TimeStamp
        Converts this TimeStamp to posix milliseconds.
        Specified by:
        toPosixMillis in class TimeStamp
        Returns:
        milliseconds since the epoch
      • toPosixMicros

        public long toPosixMicros()
        Description copied from class: TimeStamp
        Converts this TimeStamp to posix microseconds.
        Specified by:
        toPosixMicros in class TimeStamp
        Returns:
        microseconds since the epoch
      • toPosixNanos

        public long toPosixNanos()
        Description copied from class: TimeStamp
        Converts this TimeStamp to posix nanoseconds.
        Specified by:
        toPosixNanos in class TimeStamp
        Returns:
        nanoseconds since the epoch
      • toPosixSecondsExact

        public BigDecimal toPosixSecondsExact()
        Description copied from class: TimeStamp
        Converts this TimeStamp to posix seconds. The returned representation is exact (see note). NOTE: In theory, it is possible to have a subclass that stores its value in a form that cannot be exactly converted to a BigDecimal (e.g., thirds of a second). Such subclasses are discouraged. If such a subclass is unavoidable, its documentation must note prominently that it breaks the contract of the TimeStamp interface, and its implementation of this method must return values as exact as is practical.
        Specified by:
        toPosixSecondsExact in class TimeStamp
        Returns:
        seconds since the epoch
      • isBefore

        public boolean isBefore​(TimeStamp o)
        Description copied from class: TimeStamp
        Returns true iff this timestamp is before the given timestamp.
        Overrides:
        isBefore in class TimeStamp
      • isAfter

        public boolean isAfter​(TimeStamp o)
        Description copied from class: TimeStamp
        Returns true iff this timestamp is after the given timestamp.
        Overrides:
        isAfter in class TimeStamp