Update timestamp to fix some lingering issues by copying over code again from java.sql.Timestamp.

This commit is contained in:
Greg Burd 2019-11-21 21:25:33 -05:00
parent 262bba3a02
commit 048f8c65f0

View file

@ -14,9 +14,9 @@
package com.sleepycat.je.utilint; package com.sleepycat.je.utilint;
/** /**
* Duplicate of java.sql.Timestamp which keeps our implementation constant in * Duplicate of java.sql.Timestamp
* case the java.sql.Timestamp implementation changes incompatibly. This way * This duplicate keeps our implementation constant in case the java.sql.Timestamp implementation
* we can write it to disk and not worry about upgrading the log file. * changes incompatibly. This way we can write it to disk and not worry about upgrading the log file.
*/ */
public class Timestamp extends java.util.Date { public class Timestamp extends java.util.Date {
@ -24,6 +24,13 @@ public class Timestamp extends java.util.Date {
private int nanos; private int nanos;
/**
* Constructs a {@code Timestamp} object using milliseconds as the time value. Stores the integral seconds in the
* underlying date value; stores the fractional seconds in the {@code nanos} field of the {@code Timestamp} object.
*
* @param time milliseconds since January 1, 1970, 00:00:00 GMT.
* A negative number represents milliseconds before January 1, 1970, 00:00:00 GMT.
*/
public Timestamp(long time) { public Timestamp(long time) {
super((time / 1000) * 1000); super((time / 1000) * 1000);
nanos = (int) ((time % 1000) * 1000000); nanos = (int) ((time % 1000) * 1000000);
@ -33,13 +40,28 @@ public class Timestamp extends java.util.Date {
} }
} }
/**
* Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT
* represented by this {@code Timestamp} object.
*
* @return the number of milliseconds since January 1, 1970, 00:00:00 GMT
* represented by this date.
* @see #setTime
*/
public long getTime() { public long getTime() {
long time = super.getTime(); long time = super.getTime();
return (time + (nanos / 1000000)); return (time + (nanos / 1000000));
} }
/**
* Formats a timestamp in timestamp escape format.
* {@code yyyy-mm-dd hh:mm:ss.fffffffff},
* where {@code fffffffff} indicates nanoseconds.
*
* @return a {@code String} object in
* {@code yyyy-mm-dd hh:mm:ss.fffffffff} format
*/
public String toString() { public String toString() {
int year = super.getYear() + 1900; int year = super.getYear() + 1900;
int month = super.getMonth() + 1; int month = super.getMonth() + 1;
int day = super.getDate(); int day = super.getDate();