Class TimestampType

java.lang.Object
org.voltdb.types.TimestampType
All Implemented Interfaces:
Comparable<TimestampType>, org.json_voltpatches.JSONString

public class TimestampType extends Object implements org.json_voltpatches.JSONString, Comparable<TimestampType>
Represent a microsecond-accurate VoltDB timestamp type.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create a TimestampType instance for the current time.
    TimestampType(long timestamp)
    Create a TimestampType from microseconds from epoch.
    Construct from a timestamp string in a complete date or time format.
    Create a TimestampType from a Java Date class.
  • Method Summary

    Modifier and Type
    Method
    Description
    Retrieve a copy of the approximate Java date.
    Retrieve a copy of the Java date for a TimeStamp with millisecond granularity.
    Retrieve a properly typed copy of the Java date for a TimeStamp with millisecond granularity.
    Retrieve a properly typed copy of the Java Timestamp for the VoltDB TimeStamp.
    int
    CompareTo - to mimic Java Date
    boolean
    Equality.
    long
    Read the microsecond in time stored by this timestamp.
    short
    Get the microsecond portion of this timestamp
    int
    Hashcode with the same uniqueness as a Java Date.
    static long
    Given a string parseable by the JDBC Timestamp parser, return the fractional component in milliseconds.
     
    An implementation of toString for debugging and printing VoltTables.
    An implementation of toString for debugging and printing VoltTables which allows the specification of a timezone.

    Methods inherited from class java.lang.Object

    getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • TimestampType

      public TimestampType(long timestamp)
      Create a TimestampType from microseconds from epoch.
      Parameters:
      timestamp - microseconds since epoch.
    • TimestampType

      public TimestampType(Date date)
      Create a TimestampType from a Java Date class. Microseconds will be rounded to zero.
      Parameters:
      date - Java Date instance.
    • TimestampType

      public TimestampType(String param)
      Construct from a timestamp string in a complete date or time format. This is typically used for reading CSV data or data output from Timestamp's string format.
      Parameters:
      param - A string in one of these formats: "YYYY-MM-DD", "YYYY-MM-DD HH:MM:SS", OR "YYYY-MM-DD HH:MM:SS.sss" with sss allowed to be from 0 up to 6 significant digits.
    • TimestampType

      public TimestampType()
      Create a TimestampType instance for the current time.
  • Method Details

    • millisFromJDBCformat

      public static long millisFromJDBCformat(String param)
      Given a string parseable by the JDBC Timestamp parser, return the fractional component in milliseconds.
      Parameters:
      param - A timstamp in string format that is parseable by JDBC.
      Returns:
      The fraction of a second portion of this timestamp expressed in milliseconds.
      Throws:
      IllegalArgumentException - if the timestamp uses higher than millisecond precision.
    • getTime

      public long getTime()
      Read the microsecond in time stored by this timestamp.
      Returns:
      microseconds
    • getUSec

      public short getUSec()
      Get the microsecond portion of this timestamp
      Returns:
      Microsecond portion of timestamp as a short
    • equals

      public boolean equals(Object o)
      Equality.
      Overrides:
      equals in class Object
      Returns:
      true if equal.
    • toString

      public String toString()
      An implementation of toString for debugging and printing VoltTables. This formats the timestamp value using a standard ODBC date format, similar to ISO-8601. The format is yyyy-MM-dd HH:mm:ss.SSSSSS. Here, unlike the Java SimpleDateFormat formatter, the SSSSSS part is the number of microseconds. The timezone is the default timezone of the JVM. This will be the timezone of the application, which may not match the timezone of the database server. See the overload of this function which accepts a time zone for more control over the specification of the timezone.
      Overrides:
      toString in class Object
    • toString

      public String toString(TimeZone zone)
      An implementation of toString for debugging and printing VoltTables which allows the specification of a timezone.
      Parameters:
      zone - Desired timezone.
      Returns:
      A string with the time in ODBC format with the desired timezone.
    • hashCode

      public int hashCode()
      Hashcode with the same uniqueness as a Java Date.
      Overrides:
      hashCode in class Object
    • compareTo

      public int compareTo(TimestampType dateval)
      CompareTo - to mimic Java Date
      Specified by:
      compareTo in interface Comparable<TimestampType>
    • asApproximateJavaDate

      public Date asApproximateJavaDate()
      Retrieve a copy of the approximate Java date. The returned date is a copy; this object will not be affected by modifications of the returned instance.
      Returns:
      Clone of underlying Date object.
    • asExactJavaDate

      public Date asExactJavaDate()
      Retrieve a copy of the Java date for a TimeStamp with millisecond granularity. The returned date is a copy; this object will not be affected by modifications of the returned instance.
      Returns:
      Clone of underlying Date object.
    • asExactJavaSqlDate

      public Date asExactJavaSqlDate()
      Retrieve a properly typed copy of the Java date for a TimeStamp with millisecond granularity. The returned date is a copy; this object will not be affected by modifications of the returned instance.
      Returns:
      specifically typed copy of underlying Date object.
    • asJavaTimestamp

      public Timestamp asJavaTimestamp()
      Retrieve a properly typed copy of the Java Timestamp for the VoltDB TimeStamp. The returned Timestamp is a copy; this object will not be affected by modifications of the returned instance.
      Returns:
      reformatted Timestamp expressed internally as 1000s of nanoseconds.
    • toJSONString

      public String toJSONString()
      Specified by:
      toJSONString in interface org.json_voltpatches.JSONString