Class TimestampUtils
- java.lang.Object
-
- org.apache.beam.sdk.io.gcp.spanner.changestreams.restriction.TimestampUtils
-
public class TimestampUtils extends java.lang.ObjectProvides methods in order to convert timestamp to nanoseconds representation and back. Provides method to increment a given timestamp nanoseconds by 1.
-
-
Constructor Summary
Constructors Constructor Description TimestampUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static com.google.cloud.Timestampnext(com.google.cloud.Timestamp timestamp)Adds one nanosecond to the given timestamp.static com.google.cloud.Timestampprevious(com.google.cloud.Timestamp timestamp)static java.math.BigDecimaltoNanos(com.google.cloud.Timestamp timestamp)Converts the given timestamp to respective nanoseconds representation.static com.google.cloud.TimestamptoTimestamp(java.math.BigDecimal bigDecimal)Converts nanoseconds to their respective timestamp.
-
-
-
Method Detail
-
toNanos
public static java.math.BigDecimal toNanos(com.google.cloud.Timestamp timestamp)
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_VALUEseconds by adding the absolute value.- Parameters:
timestamp- the timestamp to be converted- Returns:
- positive number of nanoseconds from the
Timestamp.MIN_VALUE
-
toTimestamp
public static com.google.cloud.Timestamp toTimestamp(java.math.BigDecimal bigDecimal)
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_VALUEis 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)
-
-