add a test for datetime subtraction with fractional seconds

Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
Gavin King 2024-05-02 18:14:53 +02:00
parent 5941aca7ac
commit 8c6241a7d7
1 changed files with 16 additions and 1 deletions

View File

@ -66,7 +66,6 @@ import static org.hamcrest.Matchers.isOneOf;
import static org.hibernate.testing.orm.domain.gambit.EntityOfBasics.Gender.FEMALE;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assertions.assertThrows;
@ -1326,6 +1325,22 @@ public class FunctionTests {
);
}
@Test
@SkipForDialect(dialectClass = SybaseDialect.class, matchSubTypes = true)
public void testDiffMillisecondsAndNanoseconds(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
assertThat(
session.createQuery("select (datetime 1974-03-23 00:00:15 - datetime 1974-03-23 00:00:12.123) by second", Long.class)
.getSingleResult(),
anyOf(is(3L),is(2L)));
assertEquals(2_877_000_000L,
session.createQuery("select (datetime 1974-03-23 00:00:15 - datetime 1974-03-23 00:00:12.123) by nanosecond", Long.class)
.getSingleResult());
}
);
}
@Test
public void testTimestampAddDiffFunctions(SessionFactoryScope scope) {
scope.inTransaction(