Class TimeStampPosixMicrosInt64
- java.lang.Object
-
- com.metsci.glimpse.util.units.time.TimeStamp
-
- com.metsci.glimpse.util.units.time.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
-
-
Field Summary
Fields Modifier and Type Field Description static TimeStampFactory<TimeStampPosixMicrosInt64>factory-
Fields inherited from class com.metsci.glimpse.util.units.time.TimeStamp
defaultFormat
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description TimeStampPosixMicrosInt64add(double duration)Creates a new TimeStamp instance offset from this timestamp by the given amount.intcompareTo(TimeStamp o)doubledurationAfter(TimeStamp o)Determines how long after the given timestamp this timestamp is.doubledurationBefore(TimeStamp o)Determines how long before the given timestamp this timestamp is.booleanequals(Object o)inthashCode()booleanisAfter(TimeStamp o)Returns true iff this timestamp is after the given timestamp.booleanisBefore(TimeStamp o)Returns true iff this timestamp is before the given timestamp.TimeStampPosixMicrosInt64subtract(double duration)Creates a new TimeStamp instance offset from this timestamp by the given amount.CalendartoCalendar()Converts this TimeStamp to aCalendar.DatetoDate()Converts this TimeStamp to aDate.longtoPosixMicros()Converts this TimeStamp to posix microseconds.longtoPosixMillis()Converts this TimeStamp to posix milliseconds.longtoPosixNanos()Converts this TimeStamp to posix nanoseconds.doubletoPosixSeconds()Converts this TimeStamp to posix seconds.BigDecimaltoPosixSecondsExact()Converts this TimeStamp to posix seconds.-
Methods inherited from class com.metsci.glimpse.util.units.time.TimeStamp
currentTime, fromCalendar, fromDate, fromPosixMicros, fromPosixMillis, fromPosixNanos, fromPosixSeconds, fromPosixSeconds, fromString, fromString, fromTimeStamp, isAfterOrEquals, isBeforeOrEquals, posixEpoch, toString, toString
-
-
-
-
Field Detail
-
factory
public static final TimeStampFactory<TimeStampPosixMicrosInt64> factory
-
-
Method Detail
-
add
public TimeStampPosixMicrosInt64 add(double duration)
Description copied from class:TimeStampCreates 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.
-
subtract
public TimeStampPosixMicrosInt64 subtract(double duration)
Description copied from class:TimeStampCreates 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.
-
durationBefore
public double durationBefore(TimeStamp o)
Description copied from class:TimeStampDetermines 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:
durationBeforein classTimeStamp- Returns:
- the difference, in system-units
-
durationAfter
public double durationAfter(TimeStamp o)
Description copied from class:TimeStampDetermines 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:
durationAfterin classTimeStamp- Returns:
- the difference, in system-units
-
toPosixSeconds
public double toPosixSeconds()
Description copied from class:TimeStampConverts this TimeStamp to posix seconds.- Specified by:
toPosixSecondsin classTimeStamp- Returns:
- seconds since the epoch
-
toPosixMillis
public long toPosixMillis()
Description copied from class:TimeStampConverts this TimeStamp to posix milliseconds.- Specified by:
toPosixMillisin classTimeStamp- Returns:
- milliseconds since the epoch
-
toPosixMicros
public long toPosixMicros()
Description copied from class:TimeStampConverts this TimeStamp to posix microseconds.- Specified by:
toPosixMicrosin classTimeStamp- Returns:
- microseconds since the epoch
-
toPosixNanos
public long toPosixNanos()
Description copied from class:TimeStampConverts this TimeStamp to posix nanoseconds.- Specified by:
toPosixNanosin classTimeStamp- Returns:
- nanoseconds since the epoch
-
toDate
public Date toDate()
Description copied from class:TimeStampConverts this TimeStamp to aDate.
-
toCalendar
public Calendar toCalendar()
Description copied from class:TimeStampConverts this TimeStamp to aCalendar.- Specified by:
toCalendarin classTimeStamp
-
toPosixSecondsExact
public BigDecimal toPosixSecondsExact()
Description copied from class:TimeStampConverts 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:
toPosixSecondsExactin classTimeStamp- Returns:
- seconds since the epoch
-
isBefore
public boolean isBefore(TimeStamp o)
Description copied from class:TimeStampReturns true iff this timestamp is before the given timestamp.
-
isAfter
public boolean isAfter(TimeStamp o)
Description copied from class:TimeStampReturns true iff this timestamp is after the given timestamp.
-
compareTo
public int compareTo(TimeStamp o)
- Specified by:
compareToin interfaceComparable<TimeStamp>- Overrides:
compareToin classTimeStamp
-
-