HHH-17460 - Ongoing JPA 32 work

This commit is contained in:
Andrea Boriero 2024-04-02 17:56:00 +02:00 committed by Steve Ebersole
parent 894a182798
commit 7659c79f7a
7 changed files with 65 additions and 34 deletions

View File

@ -1,5 +1,6 @@
package org.hibernate.orm.test.timezones;
import java.time.Instant;
import java.time.OffsetDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
@ -53,13 +54,17 @@ public class AutoZonedTest {
scope.inSession( s -> {
Zoned z = s.find(Zoned.class, id);
final Dialect dialect = scope.getSessionFactory().getJdbcServices().getDialect();
Instant expected = DateTimeUtils.adjustToDefaultPrecision( nowZoned.toInstant(), dialect );
Instant actual = DateTimeUtils.adjustToDefaultPrecision( z.zonedDateTime.toInstant(), dialect );
assertEquals(
DateTimeUtils.roundToDefaultPrecision( nowZoned.toInstant(), dialect ),
DateTimeUtils.roundToDefaultPrecision( z.zonedDateTime.toInstant(), dialect )
expected,
actual
);
expected = DateTimeUtils.adjustToDefaultPrecision( nowOffset.toInstant(), dialect );
actual = DateTimeUtils.adjustToDefaultPrecision( z.offsetDateTime.toInstant(), dialect );
assertEquals(
DateTimeUtils.roundToDefaultPrecision( nowOffset.toInstant(), dialect ),
DateTimeUtils.roundToDefaultPrecision( z.offsetDateTime.toInstant(), dialect )
expected,
actual
);
assertEquals( nowZoned.toOffsetDateTime().getOffset(), z.zonedDateTime.toOffsetDateTime().getOffset() );
assertEquals( nowOffset.getOffset(), z.offsetDateTime.getOffset() );

View File

@ -1,5 +1,6 @@
package org.hibernate.orm.test.timezones;
import java.time.Instant;
import java.time.OffsetDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
@ -53,13 +54,17 @@ public class ColumnZonedTest {
scope.inSession( s -> {
Zoned z = s.find(Zoned.class, id);
final Dialect dialect = scope.getSessionFactory().getJdbcServices().getDialect();
Instant expected = DateTimeUtils.adjustToDefaultPrecision( nowZoned.toInstant(), dialect );
Instant actual = DateTimeUtils.adjustToDefaultPrecision( z.zonedDateTime.toInstant(), dialect );
assertEquals(
DateTimeUtils.roundToDefaultPrecision( nowZoned.toInstant(), dialect ),
DateTimeUtils.roundToDefaultPrecision( z.zonedDateTime.toInstant(), dialect )
expected,
actual
);
expected = DateTimeUtils.adjustToDefaultPrecision( nowOffset.toInstant(), dialect );
actual = DateTimeUtils.adjustToDefaultPrecision( z.offsetDateTime.toInstant(), dialect );
assertEquals(
DateTimeUtils.roundToDefaultPrecision( nowOffset.toInstant(), dialect ),
DateTimeUtils.roundToDefaultPrecision( z.offsetDateTime.toInstant(), dialect )
expected,
actual
);
assertEquals( nowZoned.toOffsetDateTime().getOffset(), z.zonedDateTime.toOffsetDateTime().getOffset() );
assertEquals( nowOffset.getOffset(), z.offsetDateTime.getOffset() );

View File

@ -1,5 +1,6 @@
package org.hibernate.orm.test.timezones;
import java.time.Instant;
import java.time.OffsetDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
@ -50,13 +51,17 @@ public class DefaultZonedTest {
scope.inSession( s -> {
Zoned z = s.find(Zoned.class, id);
final Dialect dialect = scope.getSessionFactory().getJdbcServices().getDialect();
Instant expected = DateTimeUtils.adjustToDefaultPrecision( nowZoned.toInstant(), dialect );
Instant actual = DateTimeUtils.adjustToDefaultPrecision( z.zonedDateTime.toInstant(), dialect );
assertEquals(
DateTimeUtils.roundToDefaultPrecision( nowZoned.toInstant(), dialect ),
DateTimeUtils.roundToDefaultPrecision( z.zonedDateTime.toInstant(), dialect )
expected,
actual
);
expected = DateTimeUtils.adjustToDefaultPrecision( nowOffset.toInstant(), dialect );
actual = DateTimeUtils.adjustToDefaultPrecision( z.offsetDateTime.toInstant(), dialect );
assertEquals(
DateTimeUtils.roundToDefaultPrecision( nowOffset.toInstant(), dialect ),
DateTimeUtils.roundToDefaultPrecision( z.offsetDateTime.toInstant(), dialect )
expected,
actual
);
if ( dialect.getTimeZoneSupport() == TimeZoneSupport.NATIVE ) {
assertEquals( nowZoned.toOffsetDateTime().getOffset(), z.zonedDateTime.toOffsetDateTime().getOffset() );

View File

@ -57,13 +57,17 @@ public class JDBCTimeZoneZonedTest {
ZoneId systemZone = ZoneId.systemDefault();
ZoneOffset systemOffset = systemZone.getRules().getOffset( Instant.now() );
final Dialect dialect = scope.getSessionFactory().getJdbcServices().getDialect();
Instant expected = DateTimeUtils.adjustToDefaultPrecision( nowZoned.toInstant(), dialect );
Instant actual = DateTimeUtils.adjustToDefaultPrecision( z.zonedDateTime.toInstant(), dialect );
assertEquals(
DateTimeUtils.roundToDefaultPrecision( nowZoned.toInstant(), dialect ),
DateTimeUtils.roundToDefaultPrecision( z.zonedDateTime.toInstant(), dialect )
expected,
actual
);
expected = DateTimeUtils.adjustToDefaultPrecision( nowOffset.toInstant(), dialect );
actual = DateTimeUtils.adjustToDefaultPrecision( z.offsetDateTime.toInstant(), dialect );
assertEquals(
DateTimeUtils.roundToDefaultPrecision( nowOffset.toInstant(), dialect ),
DateTimeUtils.roundToDefaultPrecision( z.offsetDateTime.toInstant(), dialect )
expected,
actual
);
assertEquals( systemZone, z.zonedDateTime.getZone() );
assertEquals( systemOffset, z.offsetDateTime.getOffset() );

View File

@ -56,13 +56,17 @@ public class PassThruZonedTest {
ZoneId systemZone = ZoneId.systemDefault();
ZoneOffset systemOffset = systemZone.getRules().getOffset( Instant.now() );
final Dialect dialect = scope.getSessionFactory().getJdbcServices().getDialect();
Instant expected = DateTimeUtils.adjustToDefaultPrecision( nowZoned.toInstant(), dialect );
Instant actual = DateTimeUtils.adjustToDefaultPrecision( z.zonedDateTime.toInstant(), dialect );
assertEquals(
DateTimeUtils.roundToDefaultPrecision( nowZoned.toInstant(), dialect ),
DateTimeUtils.roundToDefaultPrecision( z.zonedDateTime.toInstant(), dialect )
expected,
actual
);
expected = DateTimeUtils.adjustToDefaultPrecision( nowOffset.toInstant(), dialect );
actual = DateTimeUtils.adjustToDefaultPrecision( z.offsetDateTime.toInstant(), dialect );
assertEquals(
DateTimeUtils.roundToDefaultPrecision( nowOffset.toInstant(), dialect ),
DateTimeUtils.roundToDefaultPrecision( z.offsetDateTime.toInstant(), dialect )
expected,
actual
);
assertEquals( systemZone, z.zonedDateTime.getZone() );
assertEquals( systemOffset, z.offsetDateTime.getOffset() );

View File

@ -46,12 +46,12 @@ public class UTCNormalizedInstantTest {
final Zoned z = s.find(Zoned.class, id);
final Dialect dialect = scope.getSessionFactory().getJdbcServices().getDialect();
assertEquals(
DateTimeUtils.roundToDefaultPrecision( z.utcInstant, dialect ),
DateTimeUtils.roundToDefaultPrecision( instant, dialect )
DateTimeUtils.adjustToDefaultPrecision( z.utcInstant, dialect ),
DateTimeUtils.adjustToDefaultPrecision( instant, dialect )
);
assertEquals(
DateTimeUtils.roundToDefaultPrecision( z.localInstant, dialect ),
DateTimeUtils.roundToDefaultPrecision( instant, dialect )
DateTimeUtils.adjustToDefaultPrecision( z.localInstant, dialect ),
DateTimeUtils.adjustToDefaultPrecision( instant, dialect )
);
});
}
@ -79,13 +79,16 @@ public class UTCNormalizedInstantTest {
scope.inSession( s-> {
final Zoned z = s.find(Zoned.class, id);
final Dialect dialect = scope.getSessionFactory().getJdbcServices().getDialect();
Instant expected = DateTimeUtils.adjustToDefaultPrecision( z.utcInstant, dialect );
Instant actual = DateTimeUtils.adjustToDefaultPrecision( instant, dialect );
assertEquals(
DateTimeUtils.roundToDefaultPrecision( z.utcInstant, dialect ),
DateTimeUtils.roundToDefaultPrecision( instant, dialect )
expected,
actual
);
expected = DateTimeUtils.adjustToDefaultPrecision( z.localInstant, dialect );
assertEquals(
DateTimeUtils.roundToDefaultPrecision( z.localInstant, dialect ),
DateTimeUtils.roundToDefaultPrecision( instant, dialect )
expected,
actual
);
});
}

View File

@ -1,5 +1,6 @@
package org.hibernate.orm.test.timezones;
import java.time.Instant;
import java.time.OffsetDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
@ -53,13 +54,17 @@ public class UTCNormalizedZonedTest {
scope.inSession( s-> {
Zoned z = s.find(Zoned.class, id);
final Dialect dialect = scope.getSessionFactory().getJdbcServices().getDialect();
Instant expected = DateTimeUtils.adjustToDefaultPrecision( nowZoned.toInstant(), dialect );
Instant actual = DateTimeUtils.adjustToDefaultPrecision( z.zonedDateTime.toInstant(), dialect );
assertEquals(
DateTimeUtils.roundToDefaultPrecision( nowZoned.toInstant(), dialect ),
DateTimeUtils.roundToDefaultPrecision( z.zonedDateTime.toInstant(), dialect )
expected,
actual
);
expected = DateTimeUtils.adjustToDefaultPrecision( nowOffset.toInstant(), dialect );
actual = DateTimeUtils.adjustToDefaultPrecision( z.offsetDateTime.toInstant(), dialect );
assertEquals(
DateTimeUtils.roundToDefaultPrecision( nowOffset.toInstant(), dialect ),
DateTimeUtils.roundToDefaultPrecision( z.offsetDateTime.toInstant(), dialect )
expected,
actual
);
assertEquals( ZoneId.of("Z"), z.zonedDateTime.getZone() );
assertEquals( ZoneOffset.ofHours(0), z.offsetDateTime.getOffset() );