提交 d7aa67f5 authored 作者: Noel Grandin's avatar Noel Grandin

comment some of the TIMESTAMP code better

上级 2a871b0b
...@@ -10,7 +10,7 @@ import org.h2.util.DateTimeUtils; ...@@ -10,7 +10,7 @@ import org.h2.util.DateTimeUtils;
import org.h2.util.StringUtils; import org.h2.util.StringUtils;
/** /**
* How we expose "DATETIME WITH TIMEZONE" in our ResultSets. * How we expose "TIMESTAMP WITH TIMEZONE" in our ResultSets.
*/ */
public class TimestampWithTimeZone implements Serializable, Cloneable { public class TimestampWithTimeZone implements Serializable, Cloneable {
...@@ -170,27 +170,29 @@ public class TimestampWithTimeZone implements Serializable, Cloneable { ...@@ -170,27 +170,29 @@ public class TimestampWithTimeZone implements Serializable, Cloneable {
@Override @Override
public int hashCode() { public int hashCode() {
return 31 * super.hashCode() + timeZoneOffsetMins; final int prime = 31;
int result = 1;
result = prime * result + (int) (dateValue ^ (dateValue >>> 32));
result = prime * result + (int) (timeNanos ^ (timeNanos >>> 32));
result = prime * result + timeZoneOffsetMins;
return result;
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (this == obj) { if (this == obj)
return true; return true;
} if (obj == null)
if (getClass() != obj.getClass()) { return false;
if (getClass() != obj.getClass())
return false; return false;
}
TimestampWithTimeZone other = (TimestampWithTimeZone) obj; TimestampWithTimeZone other = (TimestampWithTimeZone) obj;
if (dateValue != other.dateValue) { if (dateValue != other.dateValue)
return false; return false;
} if (timeNanos != other.timeNanos)
if (timeNanos != other.timeNanos) {
return false; return false;
} if (timeZoneOffsetMins != other.timeZoneOffsetMins)
if (timeZoneOffsetMins != other.timeZoneOffsetMins) {
return false; return false;
}
return true; return true;
} }
......
...@@ -30,8 +30,14 @@ public class ValueTime extends Value { ...@@ -30,8 +30,14 @@ public class ValueTime extends Value {
*/ */
static final int DISPLAY_SIZE = 8; static final int DISPLAY_SIZE = 8;
/**
* Nanoseconds since midnight
*/
private final long nanos; private final long nanos;
/**
* @param nanos nanoseconds since midnight
*/
private ValueTime(long nanos) { private ValueTime(long nanos) {
this.nanos = nanos; this.nanos = nanos;
} }
...@@ -39,7 +45,7 @@ public class ValueTime extends Value { ...@@ -39,7 +45,7 @@ public class ValueTime extends Value {
/** /**
* Get or create a time value. * Get or create a time value.
* *
* @param nanos the nanoseconds * @param nanos the nanoseconds since midnight
* @return the value * @return the value
*/ */
public static ValueTime fromNanos(long nanos) { public static ValueTime fromNanos(long nanos) {
...@@ -73,7 +79,6 @@ public class ValueTime extends Value { ...@@ -73,7 +79,6 @@ public class ValueTime extends Value {
* @param s the string to parse * @param s the string to parse
* @return the time * @return the time
*/ */
public static ValueTime parse(String s) { public static ValueTime parse(String s) {
try { try {
return fromNanos(DateTimeUtils.parseTimeNanos(s, 0, s.length(), false)); return fromNanos(DateTimeUtils.parseTimeNanos(s, 0, s.length(), false));
...@@ -83,6 +88,9 @@ public class ValueTime extends Value { ...@@ -83,6 +88,9 @@ public class ValueTime extends Value {
} }
} }
/**
* @return nanoseconds since midnight
*/
public long getNanos() { public long getNanos() {
return nanos; return nanos;
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论