Class TimestampUtils
java.lang.Object
org.apache.beam.sdk.io.gcp.spanner.changestreams.restriction.TimestampUtils
Provides methods in order to convert timestamp to nanoseconds representation and back. Provides
method to increment a given timestamp nanoseconds by 1.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic com.google.cloud.Timestamp
next
(com.google.cloud.Timestamp timestamp) Adds one nanosecond to the given timestamp.static com.google.cloud.Timestamp
previous
(com.google.cloud.Timestamp timestamp) static BigDecimal
toNanos
(com.google.cloud.Timestamp timestamp) Converts the given timestamp to respective nanoseconds representation.static com.google.cloud.Timestamp
toTimestamp
(BigDecimal bigDecimal) Converts nanoseconds to their respective timestamp.
-
Constructor Details
-
TimestampUtils
public TimestampUtils()
-
-
Method Details
-
toNanos
Converts the given timestamp to respective nanoseconds representation. This method always returns a value >= 0.Since the seconds part of a timestamp can be negative (if the timestamp represents a date earlier than 1970-01-01), seconds are shifted by
Timestamp.MIN_VALUE
seconds by adding the absolute value.- Parameters:
timestamp
- the timestamp to be converted- Returns:
- positive number of nanoseconds from the
Timestamp.MIN_VALUE
-
toTimestamp
Converts nanoseconds to their respective timestamp. It is assumed that the seconds part represent the number of seconds from theTimestamp.MIN_VALUE
. Thus, when converting, they are shifted back to 1970-01-01, by subtracting the given seconds by the absolute value of seconds fromTimestamp.MIN_VALUE
.- Parameters:
bigDecimal
- the nanoseconds representation of a timestamp (fromTimestamp.MIN_VALUE
)- Returns:
- the converted timestamp
-
next
public static com.google.cloud.Timestamp next(com.google.cloud.Timestamp timestamp) Adds one nanosecond to the given timestamp. If the timestamp given isTimestamp.MAX_VALUE
,Timestamp.MAX_VALUE
is returned.- Parameters:
timestamp
- the timestamp to have one nanosecond added to- Returns:
- input timestamp + 1 nanosecond
-
previous
public static com.google.cloud.Timestamp previous(com.google.cloud.Timestamp timestamp)
-