Unverified 提交 f80b78b6 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov 提交者: GitHub

Merge pull request #1355 from katzyn/meta

Assorted changes in MetaTable
...@@ -21,17 +21,7 @@ public final class CurrentTimestamp { ...@@ -21,17 +21,7 @@ public final class CurrentTimestamp {
* @return current timestamp * @return current timestamp
*/ */
public static ValueTimestampTimeZone get() { public static ValueTimestampTimeZone get() {
long ms = System.currentTimeMillis(); return DateTimeUtils.timestampTimeZoneFromMillis(System.currentTimeMillis());
/*
* This code intentionally does not support properly dates before UNIX
* epoch and time zone offsets with seconds because such support is not
* required for current dates.
*/
int offset = DateTimeUtils.getTimeZone().getOffset(ms);
ms += offset;
return ValueTimestampTimeZone.fromDateValueAndNanos(
DateTimeUtils.dateValueFromAbsoluteDay(ms / DateTimeUtils.MILLIS_PER_DAY),
ms % DateTimeUtils.MILLIS_PER_DAY * 1_000_000, (short) (offset / 60_000));
} }
private CurrentTimestamp() { private CurrentTimestamp() {
......
...@@ -1163,6 +1163,24 @@ public class DateTimeUtils { ...@@ -1163,6 +1163,24 @@ public class DateTimeUtils {
return ValueTimestampTimeZone.fromDateValueAndNanos(dateValue, timeNanos, (short) offsetMins); return ValueTimestampTimeZone.fromDateValueAndNanos(dateValue, timeNanos, (short) offsetMins);
} }
/**
* @param ms milliseconds since 1970-01-01 (UTC)
* @return timestamp with time zone with specified value and current time zone
*/
public static ValueTimestampTimeZone timestampTimeZoneFromMillis(long ms) {
int offset = getTimeZone().getOffset(ms);
ms += offset;
long absoluteDay = ms / MILLIS_PER_DAY;
// Round toward negative infinity
if (ms < 0 && (absoluteDay * MILLIS_PER_DAY != ms)) {
absoluteDay--;
}
return ValueTimestampTimeZone.fromDateValueAndNanos(
dateValueFromAbsoluteDay(absoluteDay),
(ms - absoluteDay * MILLIS_PER_DAY) * 1_000_000,
(short) (offset / 60_000));
}
/** /**
* Calculate the absolute day for a January, 1 of the specified year. * Calculate the absolute day for a January, 1 of the specified year.
* *
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论