提交 3a86effd authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Fix ValueTime.fromNanos(Long.MIN_VALUE).getString()

上级 b5c947e5
...@@ -200,7 +200,13 @@ public class ValueTime extends Value { ...@@ -200,7 +200,13 @@ public class ValueTime extends Value {
buff.append('-'); buff.append('-');
nanos = -nanos; nanos = -nanos;
} }
long ms = nanos / 1000000; /*
* nanos now either in range from 0 to Long.MAX_VALUE or equals to
* Long.MIN_VALUE. We need to divide nanos by 1000000 with unsigned division to
* get correct result. The simplest way to do this with such constraints is to
* divide -nanos by -1000000.
*/
long ms = -nanos / -1000000;
nanos -= ms * 1000000; nanos -= ms * 1000000;
long s = ms / 1000; long s = ms / 1000;
ms -= s * 1000; ms -= s * 1000;
......
...@@ -127,6 +127,10 @@ public class TestDate extends TestBase { ...@@ -127,6 +127,10 @@ public class TestDate extends TestBase {
ValueTime.parse("1999999:59:59.999999999").getString()); ValueTime.parse("1999999:59:59.999999999").getString());
assertEquals("-1999999:59:59.999999999", assertEquals("-1999999:59:59.999999999",
ValueTime.parse("-1999999:59:59.999999999").getString()); ValueTime.parse("-1999999:59:59.999999999").getString());
assertEquals("2562047:47:16.854775807",
ValueTime.fromNanos(Long.MAX_VALUE).getString());
assertEquals("-2562047:47:16.854775808",
ValueTime.fromNanos(Long.MIN_VALUE).getString());
ValueTime t1 = ValueTime.parse("11:11:11"); ValueTime t1 = ValueTime.parse("11:11:11");
assertEquals("11:11:11", t1.getTime().toString()); assertEquals("11:11:11", t1.getTime().toString());
assertEquals("1970-01-01", t1.getDate().toString()); assertEquals("1970-01-01", t1.getDate().toString());
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论