com.ibm.streams.operator.types

Class Timestamp

  • java.lang.Object
    • com.ibm.streams.operator.types.Timestamp
  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<Timestamp>


    public final class Timestamp
    extends java.lang.Object
    implements java.io.Serializable, java.lang.Comparable<Timestamp>
    SPL timestamp. A Timestamp represents a number of seconds and nanoseconds, where nanoseconds must be in the range 0-999,999,999. Additional an application specific machine integer identifier is provided to allow precise time calculations if the time skew across machines is known.

    Timestamp may be used as an absolute point in time, by using the convention that its value is relative to January 1, 1970, 00:00:00 GMT (UTC), the epoch. This is the standard epoch for SPL, Java and Linux. A number of utility methods exist for interacting with Java's millisecond representation of the time since the epoch, typically obtained through System.currentTimeMillis().

    A Timestamp object may also be used to represent an interval, e.g. an instance representing a delay of four seconds could be created as new Timestamp(4L, 0);.
    The Java enumeration java.unit.concurrent.TimeUnit provides standard conversion between various units of time, for example a delay of 700 milliseconds can be created as

       Timestamp delay = new Timestamp(0L,
          (int) TimeUnit.MILLISECONDS.toNanos(700L));
     
    or
       Timestamp delay = Timestamp.getTimestamp(
                  TimeUnit.MILLISECONDS.toNanos(700L));
     

    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field and Description
      static int DEFAULT_MACHINE
      Default Machine identifier (zero).
      static java.lang.String IBM_COPYRIGHT 
    • Constructor Summary

      Constructors 
      Constructor and Description
      Timestamp(long seconds, int nanoseconds)
      Construct a Timestamp with the given values and a machine identifier set to zero.
      Timestamp(long seconds, int nanoseconds, int machineId)
      Construct a Timestamp with the given values.
    • Method Summary

      Methods 
      Modifier and Type Method and Description
      Timestamp add(Timestamp delta)
      Return a Timestamp that is the result of adding the delta Timestamp to this Timestamp.
      boolean after(Timestamp ts)
      Is this Timestamp after the specified Timestamp.
      boolean before(Timestamp ts)
      Is this Timestamp before the specified Timestamp.
      int compareTo(Timestamp o)
      Compare this to another Timestamp.
      long convertTo(java.util.concurrent.TimeUnit unit)
      Convert this timestamp into the unit specified.
      static Timestamp currentTime()
      Create a Timestamp representing the current time since the epoch.
      static Timestamp currentTime(int machineId)
      Create a Timestamp representing the current time since the epoch and the give machine identifier.
      boolean equals(java.lang.Object other)
      A Timestamp is equal to another Timestamp with the same seconds and nanoseconds value.
      int getMachineId()
      Return the application specific machine identifier associated with this timestamp.
      int getNanoseconds()
      Return nanoseconds portion of the time since the epoch.
      long getSeconds()
      Return seconds portion of the time since the epoch.
      java.sql.Timestamp getSQLTimestamp()
      Return a SQL Timestamp object set from this Timestamp.
      long getTime()
      Get the value as a number of milliseconds.
      java.math.BigDecimal getTimeAsSeconds()
      Get the time in seconds (including the number of nanoseconds) as a BigDecimal.
      static Timestamp getTimestamp(java.math.BigDecimal seconds)
      Create a timestamp from a BigDecimal representing number of seconds with its machine identifier set to zero.
      static Timestamp getTimestamp(double seconds)
      Create a timestamp from a double representing number of seconds with its machine identifier set to zero.
      static Timestamp getTimestamp(long milliseconds)
      Create a Timestamp from a number of milliseconds.
      static Timestamp getTimestamp(long milliseconds, int machineId)
      Create a Timestamp from a number of milliseconds and a machine identifier.
      static Timestamp getTimestamp(java.sql.Timestamp sqlTimestamp)
      Convert a JDBC Timestamp to an SPL timestamp representation with its machine identifier set to zero.
      static Timestamp getTimestamp(java.sql.Timestamp sqlTimestamp, int machineId)
      Convert a JDBC Timestamp to an SPL timestamp representation with a specified machine identifier.
      int hashCode()
      Returns a hash code for this Timestamp.
      Timestamp subtract(Timestamp delta)
      Return a Timestamp that is the result of subtracting the delta Timestamp from this Timestamp.
      java.lang.String toString()
      Return this timestamp as a String using the SPL character encoding.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • DEFAULT_MACHINE

        public static final int DEFAULT_MACHINE
        Default Machine identifier (zero).
        See Also:
        Constant Field Values
    • Constructor Detail

      • Timestamp

        public Timestamp(long seconds,
                 int nanoseconds)
        Construct a Timestamp with the given values and a machine identifier set to zero.
        Parameters:
        seconds - Number of seconds since epoch.
        nanoseconds - Number of nanoseconds since epoch.
      • Timestamp

        public Timestamp(long seconds,
                 int nanoseconds,
                 int machineId)
        Construct a Timestamp with the given values.
        Parameters:
        seconds - Number of seconds.
        nanoseconds - Number of seconds.
        machineId - Machine identifier.
    • Method Detail

      • currentTime

        public static Timestamp currentTime()
        Create a Timestamp representing the current time since the epoch. The time is obtained from System.currentTimeMillis() and thus the resolution will at most be in milliseconds. Actual resolution is dependent on the resolution of the system clock.
        Returns:
        Timestamp set to current time relative to the epoch and machine identifier set to zero.
        See Also:
        System.currentTimeMillis()
      • currentTime

        public static Timestamp currentTime(int machineId)
        Create a Timestamp representing the current time since the epoch and the give machine identifier.
        Parameters:
        machineId - Machine identifier.
        Returns:
        Timestamp set to current time relative to the epoch.
        See Also:
        System.currentTimeMillis()
      • getTimestamp

        public static Timestamp getTimestamp(long milliseconds)
        Create a Timestamp from a number of milliseconds. This may be used to generate Timestamp objects using a value that represents the number of milliseconds since the epoch.
        Parameters:
        milliseconds - number of milliseconds.
        Returns:
        New Timestamp object set from milliseconds with machineId set to zero
        See Also:
        Date.getTime()
      • getTimestamp

        public static Timestamp getTimestamp(long milliseconds,
                             int machineId)
        Create a Timestamp from a number of milliseconds and a machine identifier. This may be used to generate Timestamp objects using a value that represents the number of milliseconds since the epoch.
        Parameters:
        milliseconds - number of milliseconds.
        machineId - Machine identifier.
        Returns:
        New Timestamp object
        See Also:
        Date.getTime()
      • getTimestamp

        public static Timestamp getTimestamp(java.sql.Timestamp sqlTimestamp)
        Convert a JDBC Timestamp to an SPL timestamp representation with its machine identifier set to zero. JDBC timestamps have the same resolution as this class.
        Parameters:
        sqlTimestamp - Value to convert from.
        Returns:
        The converted timestamp.
      • getTimestamp

        public static Timestamp getTimestamp(java.sql.Timestamp sqlTimestamp,
                             int machineId)
        Convert a JDBC Timestamp to an SPL timestamp representation with a specified machine identifier. JDBC timestamps have the same resolution as this class.
        Parameters:
        sqlTimestamp - Value to convert from.
        machineId - Machine identifier
        Returns:
        The converted timestamp.
      • getTimestamp

        public static Timestamp getTimestamp(double seconds)
        Create a timestamp from a double representing number of seconds with its machine identifier set to zero.
        Parameters:
        seconds - Value to set timestamp to.
        Returns:
        Timestamp object set from seconds.
      • getTimestamp

        public static Timestamp getTimestamp(java.math.BigDecimal seconds)
        Create a timestamp from a BigDecimal representing number of seconds with its machine identifier set to zero. The seconds value is rounded down to a nano-second resolution.
        Parameters:
        seconds - Value to set timestamp to.
        Returns:
        Timestamp object set from seconds.
      • getMachineId

        public int getMachineId()
        Return the application specific machine identifier associated with this timestamp.
        Returns:
        Application specific machine identifier.
      • getNanoseconds

        public int getNanoseconds()
        Return nanoseconds portion of the time since the epoch.
        Returns:
        nanoseconds portion since epoch.
      • getSeconds

        public long getSeconds()
        Return seconds portion of the time since the epoch.
        Returns:
        seconds portion since epoch.
      • getTime

        public long getTime()
        Get the value as a number of milliseconds. If this Timestamp contains a value relative to the epoch then the returned value matches the standard Java long representation of a time since the epoch.
        Returns:
        Number of milliseconds.
        See Also:
        Date.setTime(long)
      • getSQLTimestamp

        public java.sql.Timestamp getSQLTimestamp()
        Return a SQL Timestamp object set from this Timestamp.
        Returns:
        A SQL Timestamp set to the same value.
      • hashCode

        public int hashCode()
        Returns a hash code for this Timestamp. The machine identifier is not used in calculating the hash code.
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals(java.lang.Object other)
        A Timestamp is equal to another Timestamp with the same seconds and nanoseconds value. Machine identifier is ignored.
        Overrides:
        equals in class java.lang.Object
      • getTimeAsSeconds

        public java.math.BigDecimal getTimeAsSeconds()
        Get the time in seconds (including the number of nanoseconds) as a BigDecimal.
        Returns:
        A BigDecimal representing this Timestamp's value in seconds.
      • convertTo

        public long convertTo(java.util.concurrent.TimeUnit unit)
        Convert this timestamp into the unit specified.
        Parameters:
        unit -
        Returns:
        Value of this time in the converted unit.
        Throws:
        java.lang.ArithmeticException - This timestamp cannot be represented in the specified units.
      • compareTo

        public int compareTo(Timestamp o)
        Compare this to another Timestamp. Machine identifier is ignored.
        Specified by:
        compareTo in interface java.lang.Comparable<Timestamp>
      • after

        public boolean after(Timestamp ts)
        Is this Timestamp after the specified Timestamp.
        Parameters:
        ts - Timestamp to compare.
        Returns:
        True if this Timestamp is later, false otherwise.
      • before

        public boolean before(Timestamp ts)
        Is this Timestamp before the specified Timestamp.
        Parameters:
        ts - Timestamp to compare.
        Returns:
        True if this Timestamp is earlier, false otherwise.
      • subtract

        public Timestamp subtract(Timestamp delta)
        Return a Timestamp that is the result of subtracting the delta Timestamp from this Timestamp. The machine identifier for the resultant Timestamp is set to this Timestamp's machine identifier.
        Parameters:
        delta - Value to be subtracted from this.
        Returns:
        The result of the subtraction.
      • add

        public Timestamp add(Timestamp delta)
        Return a Timestamp that is the result of adding the delta Timestamp to this Timestamp. The machine identifier for the resultant Timestamp is set to this Timestamp's machine identifier.
        Parameters:
        delta - Value to be added to this.
        Returns:
        The result of the addition.
      • toString

        public java.lang.String toString()
        Return this timestamp as a String using the SPL character encoding. The value returned has the format: (seconds, nanoseconds, machineId).
        Overrides:
        toString in class java.lang.Object
        Returns:
        String representation of this timestamp using SPL character encoding.
        Since:
        InfoSphere® Streams Version 4.0