Package org.voltdb.types
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
ConstructorDescriptionCreate a TimestampType instance for the current time.TimestampType
(long timestamp) Create a TimestampType from microseconds from epoch.TimestampType
(String param) Construct from a timestamp string in a complete date or time format.TimestampType
(Date date) Create a TimestampType from a Java Date class. -
Method Summary
Modifier and TypeMethodDescriptionRetrieve 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
(TimestampType dateval) CompareTo - to mimic Java Dateboolean
Equality.long
getTime()
Read the microsecond in time stored by this timestamp.short
getUSec()
Get the microsecond portion of this timestampint
hashCode()
Hashcode with the same uniqueness as a Java Date.static long
millisFromJDBCformat
(String param) Given a string parseable by the JDBC Timestamp parser, return the fractional component in milliseconds.toString()
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.
-
Constructor Details
-
TimestampType
public TimestampType(long timestamp) Create a TimestampType from microseconds from epoch.- Parameters:
timestamp
- microseconds since epoch.
-
TimestampType
Create a TimestampType from a Java Date class. Microseconds will be rounded to zero.- Parameters:
date
- Java Date instance.
-
TimestampType
Construct from a timestamp string in a complete date or time format. This is typically used for reading CSV data or data output fromTimestamp
'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
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
Equality. -
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. -
toString
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. -
compareTo
CompareTo - to mimic Java Date- Specified by:
compareTo
in interfaceComparable<TimestampType>
-
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
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
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
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
- Specified by:
toJSONString
in interfaceorg.json_voltpatches.JSONString
-