提交 ae6da320 authored 作者: Noel Grandin's avatar Noel Grandin 提交者: GitHub

Merge pull request #523 from stumc/Issue#458

Issue#458 TIMESTAMPDIFF YEAR fix
......@@ -1887,11 +1887,11 @@ public class Function extends Expression implements FunctionCall {
calendar.setTimeInMillis(t2);
int year2 = calendar.get(Calendar.YEAR);
int month2 = calendar.get(Calendar.MONTH);
int result = year2 - year1;
int yearResult = year2 - year1;
if (field == Calendar.MONTH) {
return 12 * result + (month2 - month1);
return 12 * yearResult + (month2 - month1);
} else if (field == Calendar.YEAR) {
return result;
return (12 * yearResult + (month2 - month1))/12;
} else {
throw DbException.getUnsupportedException("DATEDIFF " + part);
}
......
......@@ -11,6 +11,7 @@ import java.io.LineNumberReader;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.h2.test.TestBase;
import org.h2.util.ScriptReader;
......@@ -72,6 +73,7 @@ public class TestScriptSimple extends TestBase {
}
conn.close();
deleteDb("scriptSimple");
}
private void reconnect() throws SQLException {
......
......@@ -9909,15 +9909,29 @@ select dateadd('year', -1, timestamp '2000-02-29 10:20:30.012345678') d1 from te
> 1999-02-28 10:20:30.012345678
> rows: 1
-- Only 2 months difference, not a whole year
select datediff('yy', timestamp '2003-12-01 10:20:30.0', timestamp '2004-01-01 10:00:00.0') d1 from test;
> D1
> --
> 0
> rows: 1
select datediff('yy', timestamp '2003-12-01 10:20:30.0', timestamp '2004-12-01 10:20:30.0') d1 from test;
> D1
> --
> 1
> rows: 1
-- Only 2 months difference, not a whole year
select datediff('year', timestamp '2003-12-01 10:20:30.0', timestamp '2004-01-01 10:00:00.0') d1 from test;
> D1
> --
> 0
> rows: 1
select datediff('year', timestamp '2003-12-01 10:20:30.0', timestamp '2004-12-01 10:20:30.0') d1 from test;
> D1
> --
> 1
> rows: 1
......
......@@ -111,6 +111,7 @@ public final class ImmutableArray<K> implements Iterable<K> {
* @param array the data
* @return the new immutable array
*/
@SafeVarargs
public static <K> ImmutableArray<K> create(K... array) {
return new ImmutableArray<K>(array);
}
......
......@@ -151,6 +151,7 @@ public final class ImmutableArray2<K> implements Iterable<K> {
* @param array the data
* @return the new immutable array
*/
@SafeVarargs
public static <K> ImmutableArray2<K> create(K... array) {
return new ImmutableArray2<K>(array, array.length);
}
......
......@@ -84,6 +84,7 @@ public abstract class ImmutableArray3<K> implements Iterable<K> {
* @param array the data
* @return the new immutable array
*/
@SafeVarargs
public static <K> ImmutableArray3<K> create(K... array) {
return new Plain<K>(array);
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论