Class TimestampUtils


  • public class TimestampUtils
    extends java.lang.Object
    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 
      Constructor Description
      TimestampUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static 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 java.math.BigDecimal toNanos​(com.google.cloud.Timestamp timestamp)
      Converts the given timestamp to respective nanoseconds representation.
      static com.google.cloud.Timestamp toTimestamp​(java.math.BigDecimal bigDecimal)
      Converts nanoseconds to their respective timestamp.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • TimestampUtils

        public TimestampUtils()
    • 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_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

        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 the Timestamp.MIN_VALUE. Thus, when converting, they are shifted back to 1970-01-01, by subtracting the given seconds by the absolute value of seconds from Timestamp.MIN_VALUE.
        Parameters:
        bigDecimal - the nanoseconds representation of a timestamp (from Timestamp.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 is Timestamp.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)