Package org.scictrl.csshell
Class Timestamp
java.lang.Object
org.scictrl.csshell.Timestamp
- All Implemented Interfaces:
Comparable<Timestamp>
This is timestamp object with nanosecond resolution. It holds two long values. One is with millisoecnd
resolution and represents Java standart UTC format. Second long value is with nanosecond resolution
and its absolute value is lower than 1ms or 1000000ns.
- Author:
- igor@scictrl.com
-
Nested Class Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionint
compareTo.boolean
long
Returns time in milliseconds since epoch (standard Java UTC time, as returned by System.currentTimeMillis())long
Getter for the fieldnanoseconds
.long
Get seconds since epoch, i.e.boolean
isGreaterOrEqual
(Timestamp other) isGreaterOrEqual.boolean
isGreaterThan
(Timestamp other) isGreaterThan.boolean
isLessOrEqual
(Timestamp other) isLessOrEqual.boolean
isLessThan
(Timestamp other) isLessThan.boolean
isValid()
isValid.double
toDouble()
Converts timestamp to double.long
Returns time in nanoseconds since epoch.toString()
toString
(Timestamp.Format format) toString.
-
Constructor Details
-
Timestamp
public Timestamp()Default constructor, uses system time for initialization. -
Timestamp
public Timestamp(long milli, long nano) Creates timestamp representing provided values. If nanoseconds exceed 1000000 or -1000000 then they are truncated to nanoseconds within millisecond and millisecond is corrected.- Parameters:
milli
- a longnano
- a long
-
-
Method Details
-
getMilliseconds
public long getMilliseconds()Returns time in milliseconds since epoch (standard Java UTC time, as returned by System.currentTimeMillis())- Returns:
- Returns the milliseconds.
-
getNanoseconds
public long getNanoseconds()Getter for the field
nanoseconds
.- Returns:
- Returns the nanoseconds within the millisecond.
-
compareTo
compareTo.
- Specified by:
compareTo
in interfaceComparable<Timestamp>
- Parameters:
o
- aTimestamp
object- Returns:
- a int
-
toNanoTime
public long toNanoTime()Returns time in nanoseconds since epoch. Not that this in only usefull for calculating time difference for up to 292 years (263 nanoseconds) since this is maximum time possible in nanoseconds due to long value range overflow.- Returns:
- up to approx. 292 years big nano time
-
equals
-
toString
-
toString
toString.
- Parameters:
format
- aTimestamp.Format
object- Returns:
- Returns timestamp as string formated as specified.
-
getSeconds
public long getSeconds()Get seconds since epoch, i.e. 1 January 1970 0:00 UTC.- Returns:
- a long
-
toDouble
public double toDouble()Converts timestamp to double.- Returns:
- a double
-
isValid
public boolean isValid()isValid.
- Returns:
- Returns
true
if time fields > 0.
-
isGreaterThan
isGreaterThan.
- Parameters:
other
- Other time stamp- Returns:
- Returns
true
if this time stamp is greater than theother
time stamp.
-
isGreaterOrEqual
isGreaterOrEqual.
- Parameters:
other
- Other time stamp- Returns:
- Returns
true
if this time stamp is greater than or equal to theother
time stamp.
-
isLessThan
isLessThan.
- Parameters:
other
- Other time stamp- Returns:
- Returns
true
if this time stamp is less than theother
time stamp.
-
isLessOrEqual
isLessOrEqual.
- Parameters:
other
- Other time stamp- Returns:
- Returns
true
if this time stamp is less than or equal to theother
time stamp.
-