com.pivotal.gemfirexd.internal.client.am

## Class DateTime

- java.lang.Object
- - com.pivotal.gemfirexd.internal.client.am.DateTime

    public class DateTime
    extends Object

High performance converters from date/time byte encodings to JDBC Date, Time and Timestamp objects.

Using this class for direct date/time conversions from bytes offers superior performance over the alternative method of first constructing a Java String from the encoded bytes, and then using `java.sql.Date.valueOf()`, `java.sql.Time.valueOf()` or `java.sql.Timestamp.valueOf()`.

### Method Summary

Methods
`static Date` `dateBytesToDate(byte[] buffer, int offset, Calendar recyclableCal, String encoding)` Expected character representation is DERBY string representation of a date, which is in JIS format: `yyyy-mm-dd`
`static Timestamp` `dateBytesToTimestamp(byte[] buffer, int offset, Calendar recyclableCal, String encoding)` Expected character representation is DERBY string representation of a date which is in JIS format: `yyyy-mm-dd`
`static int` `dateToDateBytes(byte[] buffer, int offset, Date date, Calendar cal)` Date is converted to a char representation in JDBC date format: `yyyy-mm-dd` date format and then converted to bytes using UTF8 encoding
`static int` `dateToTimestampBytes(byte[] buffer, int offset, Date date, Calendar cal)` java.sql.Date is converted to character representation that is in DERBY string representation of a timestamp:`yyyy-mm-dd-hh.mm.ss.ffffff` and then converted to bytes using UTF8 encoding and written out to the buffer
`static Time` `timeBytesToTime(byte[] buffer, int offset, Calendar recyclableCal, String encoding)` Expected character representation is DERBY string representation of time, which is in the format: `hh.mm.ss`
`static Timestamp` `timeBytesToTimestamp(byte[] buffer, int offset, Calendar recyclableCal, String encoding)` Expected character representation is DERBY string representation of time which is in the format: `hh.mm.ss`
`static Date` `timestampBytesToDate(byte[] buffer, int offset, Calendar recyclableCal, String encoding)` Expected character representation is DERBY string representation of a timestamp: `yyyy-mm-dd-hh.mm.ss.ffffff`.
`static Time` `timestampBytesToTime(byte[] buffer, int offset, Calendar recyclableCal, String encoding)` Expected character representation is DERBY string representation of a timestamp: `yyyy-mm-dd-hh.mm.ss.ffffff`.
`static Timestamp` `timestampBytesToTimestamp(byte[] buffer, int offset, Calendar recyclableCal, String encoding)` Expected character representation is DERBY string representation of a timestamp: `yyyy-mm-dd-hh.mm.ss.ffffff`.
`static int` `timestampToDateBytes(byte[] buffer, int offset, Timestamp timestamp, Calendar cal)` java.sql.Timestamp is converted to character representation that is in JDBC date escape format: `yyyy-mm-dd`, which is the same as JIS date format in DERBY string representation of a date.
`static int` `timestampToTimeBytes(byte[] buffer, int offset, Timestamp timestamp, Calendar cal)` java.sql.Timestamp is converted to character representation in JDBC time escape format: `hh:mm:ss`, which is the same as JIS time format in DERBY string representation of a time.
`static int` `timestampToTimestampBytes(byte[] buffer, int offset, Timestamp timestamp, Calendar cal)` java.sql.Timestamp is converted to a character representation which is in DERBY string representation of a timestamp: `yyyy-mm-dd-hh.mm.ss.ffffff`.
`static int` `timeToTimeBytes(byte[] buffer, int offset, Time time, Calendar cal)` java.sql.Time is converted to character representation which is in JDBC time escape format: `hh:mm:ss`, which is the same as JIS time format in DERBY string representation of a time.
`static int` `timeToTimestampBytes(byte[] buffer, int offset, Time time, Calendar cal)` java.sql.Time is converted to a character representation that is in DERBY string representation of a timestamp: `yyyy-mm-dd-hh.mm.ss.ffffff` and converted to bytes using UTF8 encoding

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Method Detail

#### dateBytesToDate

    public static final Date dateBytesToDate(byte[] buffer,
                       int offset,
                       Calendar recyclableCal,
                       String encoding)
                                      throws UnsupportedEncodingException

Expected character representation is DERBY string representation of a date, which is in JIS format: `yyyy-mm-dd`

Parameters:
  `buffer` -
  `offset` -
  `recyclableCal` -
  `encoding` - encoding of buffer data
Returns:
  Date translated from buffer with specified encoding
Throws:
  `UnsupportedEncodingException`

#### timeBytesToTime

    public static final Time timeBytesToTime(byte[] buffer,
                       int offset,
                       Calendar recyclableCal,
                       String encoding)
                                      throws UnsupportedEncodingException

Expected character representation is DERBY string representation of time, which is in the format: `hh.mm.ss`

Parameters:
  `buffer` -
  `offset` -
  `recyclableCal` -
  `encoding` - encoding of buffer
Returns:
  Time translated from buffer with specified encoding
Throws:
  `UnsupportedEncodingException`

#### timestampBytesToTimestamp

    public static final Timestamp timestampBytesToTimestamp(byte[] buffer,
                                      int offset,
                                      Calendar recyclableCal,
                                      String encoding)
                                                     throws UnsupportedEncodingException

Expected character representation is DERBY string representation of a timestamp: `yyyy-mm-dd-hh.mm.ss.ffffff`.

Parameters:
  `buffer` -
  `offset` -
  `recyclableCal` -
  `encoding` - encoding of buffer
Returns:
  TimeStamp translated from buffer with specified encoding
Throws:
  `UnsupportedEncodingException`

#### dateToDateBytes

    public static final int dateToDateBytes(byte[] buffer,
                      int offset,
                      Date date,
                      Calendar cal)
                                     throws SqlException,
                                            UnsupportedEncodingException

Date is converted to a char representation in JDBC date format: `yyyy-mm-dd` date format and then converted to bytes using UTF8 encoding

Parameters:
  `buffer` - bytes in UTF8 encoding of the date
  `offset` - write into the buffer from this offset
  `date` - date value
Returns:
  DateTime.dateRepresentationLength. This is the fixed length in bytes taken to represent the date value
Throws:
  `SqlException`
  `UnsupportedEncodingException` - if UTF8 Encoding is not supported

#### timeToTimeBytes

    public static final int timeToTimeBytes(byte[] buffer,
                      int offset,
                      Time time,
                      Calendar cal)
                                     throws UnsupportedEncodingException

java.sql.Time is converted to character representation which is in JDBC time escape format: `hh:mm:ss`, which is the same as JIS time format in DERBY string representation of a time. The char representation is converted to bytes using UTF8 encoding.

Parameters:
  `buffer` - bytes in UTF8 encoding of the time
  `offset` - write into the buffer from this offset
  `time` - java.sql.Time value
Returns:
  DateTime.timeRepresentationLength. This is the fixed length in bytes taken to represent the time value
Throws:
  `UnsupportedEncodingException`

#### timestampToTimestampBytes

    public static final int timestampToTimestampBytes(byte[] buffer,
                                int offset,
                                Timestamp timestamp,
                                Calendar cal)
                                               throws SqlException,
                                                      UnsupportedEncodingException

java.sql.Timestamp is converted to a character representation which is in DERBY string representation of a timestamp: `yyyy-mm-dd-hh.mm.ss.ffffff`. and then converted to bytes using UTF8 encoding

Parameters:
  `buffer` - bytes in UTF8 encoding of the timestamp
  `offset` - write into the buffer from this offset
  `timestamp` - timestamp value
Returns:
  DateTime.timestampRepresentationLength. This is the fixed length in bytes, taken to represent the timestamp value
Throws:
  `SqlException`
  `UnsupportedEncodingException`

#### dateBytesToTimestamp

    public static final Timestamp dateBytesToTimestamp(byte[] buffer,
                                 int offset,
                                 Calendar recyclableCal,
                                 String encoding)
                                                throws UnsupportedEncodingException

Expected character representation is DERBY string representation of a date which is in JIS format: `yyyy-mm-dd`

Parameters:
  `buffer` -
  `offset` -
  `recyclableCal` -
  `encoding` - encoding of buffer
Returns:
  Timestamp translated from buffer with specified encoding
Throws:
  `UnsupportedEncodingException`

#### timeBytesToTimestamp

    public static final Timestamp timeBytesToTimestamp(byte[] buffer,
                                 int offset,
                                 Calendar recyclableCal,
                                 String encoding)
                                                throws UnsupportedEncodingException

Expected character representation is DERBY string representation of time which is in the format: `hh.mm.ss`

Parameters:
  `buffer` -
  `offset` -
  `recyclableCal` -
  `encoding` - encoding of buffer
Returns:
  Timestamp translated from buffer with specified encoding
Throws:
  `UnsupportedEncodingException`

#### timestampBytesToDate

    public static final Date timestampBytesToDate(byte[] buffer,
                            int offset,
                            Calendar recyclableCal,
                            String encoding)
                                           throws UnsupportedEncodingException

Expected character representation is DERBY string representation of a timestamp: `yyyy-mm-dd-hh.mm.ss.ffffff`.

Parameters:
  `buffer` -
  `offset` -
  `recyclableCal` -
  `encoding` - encoding of buffer
Returns:
  Date translated from buffer with specified encoding
Throws:
  `UnsupportedEncodingException`

#### timestampBytesToTime

    public static final Time timestampBytesToTime(byte[] buffer,
                            int offset,
                            Calendar recyclableCal,
                            String encoding)
                                           throws UnsupportedEncodingException

Expected character representation is DERBY string representation of a timestamp: `yyyy-mm-dd-hh.mm.ss.ffffff`.

Parameters:
  `buffer` -
  `offset` -
  `recyclableCal` -
  `encoding` - encoding of buffer
Returns:
  Time translated from buffer with specified Encoding
Throws:
  `UnsupportedEncodingException`

#### timestampToDateBytes

    public static final int timestampToDateBytes(byte[] buffer,
                           int offset,
                           Timestamp timestamp,
                           Calendar cal)
                                          throws SqlException,
                                                 UnsupportedEncodingException

java.sql.Timestamp is converted to character representation that is in JDBC date escape format: `yyyy-mm-dd`, which is the same as JIS date format in DERBY string representation of a date. and then converted to bytes using UTF8 encoding.

Parameters:
  `buffer` -
  `offset` - write into the buffer from this offset
  `timestamp` - timestamp value
Returns:
  DateTime.dateRepresentationLength. This is the fixed length in bytes, that is taken to represent the timestamp value as a date.
Throws:
  `SqlException`
  `UnsupportedEncodingException`

#### timestampToTimeBytes

    public static final int timestampToTimeBytes(byte[] buffer,
                           int offset,
                           Timestamp timestamp,
                           Calendar cal)
                                          throws UnsupportedEncodingException

java.sql.Timestamp is converted to character representation in JDBC time escape format: `hh:mm:ss`, which is the same as JIS time format in DERBY string representation of a time. The char representation is then converted to bytes using UTF8 encoding and written out into the buffer

Parameters:
  `buffer` -
  `offset` - write into the buffer from this offset
  `timestamp` - timestamp value
Returns:
  DateTime.timeRepresentationLength. This is the fixed length in bytes taken to represent the timestamp value as Time.
Throws:
  `UnsupportedEncodingException`

#### dateToTimestampBytes

    public static final int dateToTimestampBytes(byte[] buffer,
                           int offset,
                           Date date,
                           Calendar cal)
                                          throws SqlException,
                                                 UnsupportedEncodingException

java.sql.Date is converted to character representation that is in DERBY string representation of a timestamp:`yyyy-mm-dd-hh.mm.ss.ffffff` and then converted to bytes using UTF8 encoding and written out to the buffer

Parameters:
  `buffer` -
  `offset` - offset in buffer to start writing to
  `date` - date value
Returns:
  DateTime.timestampRepresentationLength. This is the fixed length in bytes, taken to represent the timestamp value.
Throws:
  `SqlException`
  `UnsupportedEncodingException`

#### timeToTimestampBytes

    public static final int timeToTimestampBytes(byte[] buffer,
                           int offset,
                           Time time,
                           Calendar cal)
                                          throws UnsupportedEncodingException

java.sql.Time is converted to a character representation that is in DERBY string representation of a timestamp: `yyyy-mm-dd-hh.mm.ss.ffffff` and converted to bytes using UTF8 encoding

Parameters:
  `buffer` -
  `offset` - offset in buffer to start writing to
  `time` - time value
Returns:
  DateTime.timestampRepresentationLength which is the fixed length taken up by the conversion of time to timestamp in bytes
Throws:
  `UnsupportedEncodingException`