Package com.seeq.link.sdk.utilities
Class TimeInstant
java.lang.Object
com.seeq.link.sdk.utilities.TimeInstant
Representation of a Seeq timestamp which is a count of nanoseconds elapsed since Unix Epoch (January 1, 1970 UTC).
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionTimeInstant
(long timestamp) Construct a new TimeInstant with the count of nanoseconds elapsed since Unix Epoch (January 1, 1970 UTC).TimeInstant
(ZonedDateTime dateTime) Construct a new TimeInstant from a Java ZonedDateTime. -
Method Summary
Modifier and TypeMethodDescriptionstatic long
dateTimeToTimestamp
(LocalDateTime dateTime) Converts a Java LocalDateTime to a Seeq timestamp which is a count of nanoseconds elapsed since Unix Epoch (January 1, 1970 UTC).static long
dateTimeToTimestamp
(ZonedDateTime dateTime) Converts a Java ZonedDateTime to a Seeq timestamp which is a count of nanoseconds elapsed since Unix Epoch (January 1, 1970 UTC).Subtract a nanosecond from this time.long
Represents a Seeq timestamp which is a count of nanoseconds elapsed since Unix Epoch (January 1, 1970 UTC).Add a nanosecond to this time.static TimeInstant
Parses a string in the ISO format "2021-02-14T15:23:54.384758575Z" into a TimeInstant.roundDown
(long multiple_ns) Round down a TimeInstant to a multiple of nanoseconds.
Example: TimeInstant = 1232 ns.static long
roundTimestampDown
(long timestamp, long multiple) Round down a timestamp to a multiple of 1, 10, 100, etc.
Example: roundTimestampDown( 1232,100) = 1200
Example: roundTimestampDown(-1232,100) = -1300static long
roundTimestampUp
(long timestamp, long multiple) Round up a timestamp to a multiple of 1, 10, 100, etc.
Example: roundTimestampUp( 1232,100) = 1300
Example: roundTimestampUp(-1232,100) = -1200roundUp
(long multiple_ns) Round up a TimeInstant to a multiple of nanoseconds.
Example: TimeInstant = 1232 ns.static ZonedDateTime
timestampToDateTime
(long timestamp) Converts a Seeq timestamp to a Java UTC DateTime.Retrieves the TimeInstant as a Java UTC DateTime.toString()
-
Field Details
-
MIN
-
ISO_TIMESTAMP_REGEX
-
-
Constructor Details
-
TimeInstant
public TimeInstant(long timestamp) Construct a new TimeInstant with the count of nanoseconds elapsed since Unix Epoch (January 1, 1970 UTC).- Parameters:
timestamp
- Number of nanoseconds elapsed since Unix Epoch (January 1, 1970 UTC).
-
TimeInstant
Construct a new TimeInstant from a Java ZonedDateTime.- Parameters:
dateTime
- The time that the TimeInstant is to represent.
-
-
Method Details
-
getTimestamp
public long getTimestamp()Represents a Seeq timestamp which is a count of nanoseconds elapsed since Unix Epoch (January 1, 1970 UTC). Seeq timestamps are always in UTC.- Returns:
- the timestamp
-
toDateTime
Retrieves the TimeInstant as a Java UTC DateTime.- Returns:
- The Java UTC DateTime representation of the TimeInstant.
-
timestampToDateTime
Converts a Seeq timestamp to a Java UTC DateTime. Seeq timestamps are a count of nanoseconds elapsed since Unix Epoch (January 1, 1970 UTC).- Parameters:
timestamp
- Number of nanoseconds elapsed since Unix Epoch (January 1, 1970 UTC).- Returns:
- The UTC DateTime representation of the Seeq timestamp.
-
dateTimeToTimestamp
Converts a Java ZonedDateTime to a Seeq timestamp which is a count of nanoseconds elapsed since Unix Epoch (January 1, 1970 UTC).- Parameters:
dateTime
- The Java DateTime that the timestamp is to represent.- Returns:
- The Seeq timestamp representation of the .Net DateTime.
-
dateTimeToTimestamp
Converts a Java LocalDateTime to a Seeq timestamp which is a count of nanoseconds elapsed since Unix Epoch (January 1, 1970 UTC).- Parameters:
dateTime
- The Java DateTime that the timestamp is to represent.- Returns:
- The Seeq timestamp representation of the .Net DateTime.
-
roundUp
Round up a TimeInstant to a multiple of nanoseconds.
Example: TimeInstant = 1232 ns. TimeInstant.roundUp(100) = 1300 ns
Example: TimeInstant = -1232 ns. TimeInstant.roundUp(100)= -1200 ns- Parameters:
multiple_ns
- The multiple of nanoseconds to round to such as 1, 10, 100, 1000 etc- Returns:
- The rounded result
-
roundTimestampUp
public static long roundTimestampUp(long timestamp, long multiple) Round up a timestamp to a multiple of 1, 10, 100, etc.
Example: roundTimestampUp( 1232,100) = 1300
Example: roundTimestampUp(-1232,100) = -1200- Parameters:
timestamp
- The timestamp to roundmultiple
- The multiple to round to such as 1, 10, 100, 1000 etc- Returns:
- The rounded result
-
roundDown
Round down a TimeInstant to a multiple of nanoseconds.
Example: TimeInstant = 1232 ns. TimeInstant.roundUp(100) = 1200 ns
Example: TimeInstant = -1232 ns. TimeInstant.roundUp(100)= -1300 ns- Parameters:
multiple_ns
- The multiple of nanoseconds to round to such as 1, 10, 100, 1000 etc- Returns:
- The rounded result
-
decrement
Subtract a nanosecond from this time.- Returns:
- The time exactly 1 nanosecond previous to the time represented by this instance.
- Throws:
ArithmeticException
- If this timestamp is already at the minimum representable time.
-
increment
Add a nanosecond to this time.- Returns:
- The time exactly 1 nanosecond after the time represented by this instance.
- Throws:
ArithmeticException
- If this timestamp is already at the maximum representable time.
-
roundTimestampDown
public static long roundTimestampDown(long timestamp, long multiple) Round down a timestamp to a multiple of 1, 10, 100, etc.
Example: roundTimestampDown( 1232,100) = 1200
Example: roundTimestampDown(-1232,100) = -1300- Parameters:
timestamp
- The timestamp to roundmultiple
- The multiple to round to such as 1, 10, 100, 1000 etc- Returns:
- The rounded result
-
toString
-
parseIso
Parses a string in the ISO format "2021-02-14T15:23:54.384758575Z" into a TimeInstant. Note that only this string format is supported. Sub-nanosecond precision will be ignored (floored).- Parameters:
str
- A string in ISO format "2021-02-14T15:23:54.384758575Z"- Returns:
- The TimeInstant corresponding to the specified string.
-