diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/timezones/ExplicitZonedTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/timezones/JDBCTimeZoneZonedTest.java similarity index 78% rename from hibernate-core/src/test/java/org/hibernate/orm/test/timezones/ExplicitZonedTest.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/timezones/JDBCTimeZoneZonedTest.java index 3aca80d58d..d81f250fa5 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/timezones/ExplicitZonedTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/timezones/JDBCTimeZoneZonedTest.java @@ -12,6 +12,7 @@ import org.hibernate.testing.orm.junit.SessionFactoryScope; import org.hibernate.testing.orm.junit.Setting; import org.junit.jupiter.api.Test; +import java.time.Instant; import java.time.OffsetDateTime; import java.time.ZoneId; import java.time.ZoneOffset; @@ -20,11 +21,11 @@ import java.time.temporal.ChronoUnit; import static org.junit.jupiter.api.Assertions.assertEquals; -@DomainModel(annotatedClasses = ExplicitZonedTest.Zoned.class) +@DomainModel(annotatedClasses = JDBCTimeZoneZonedTest.Zoned.class) @SessionFactory @ServiceRegistry(settings = {@Setting(name = AvailableSettings.TIMEZONE_DEFAULT_STORAGE, value = "NORMALIZE"), @Setting(name = AvailableSettings.JDBC_TIME_ZONE, value = "GMT+5")}) -public class ExplicitZonedTest { +public class JDBCTimeZoneZonedTest { @Test void test(SessionFactoryScope scope) { ZonedDateTime nowZoned = ZonedDateTime.now().withZoneSameInstant( ZoneId.of("CET") ); @@ -38,17 +39,19 @@ public class ExplicitZonedTest { }); scope.inSession( s-> { Zoned z = s.find(Zoned.class, id); + ZoneId systemZone = ZoneId.systemDefault(); + ZoneOffset systemOffset = systemZone.getRules().getOffset( Instant.now() ); if ( scope.getSessionFactory().getJdbcServices().getDialect() instanceof SybaseDialect) { // Sybase with jTDS driver has 1/300th sec precision assertEquals( nowZoned.toInstant().truncatedTo(ChronoUnit.SECONDS), z.zonedDateTime.toInstant().truncatedTo(ChronoUnit.SECONDS)); assertEquals( nowOffset.toInstant().truncatedTo(ChronoUnit.SECONDS), z.offsetDateTime.toInstant().truncatedTo(ChronoUnit.SECONDS)); } else { - assertEquals( nowZoned.toInstant(), z.zonedDateTime.toInstant() ); - assertEquals( nowOffset.toInstant(), z.offsetDateTime.toInstant() ); + assertEquals( nowZoned.withZoneSameInstant(systemZone), z.zonedDateTime ); + assertEquals( nowOffset.withOffsetSameInstant(systemOffset), z.offsetDateTime ); } - assertEquals( ZoneId.systemDefault(), z.zonedDateTime.getZone() ); - assertEquals( ZoneOffset.systemDefault().normalized(), z.offsetDateTime.getOffset().normalized() ); + assertEquals( systemZone, z.zonedDateTime.getZone() ); + assertEquals( systemOffset, z.offsetDateTime.getOffset() ); }); } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/timezones/PassThruZonedTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/timezones/PassThruZonedTest.java index 88dac300d7..6eea8baa92 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/timezones/PassThruZonedTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/timezones/PassThruZonedTest.java @@ -12,6 +12,7 @@ import org.hibernate.testing.orm.junit.SessionFactoryScope; import org.hibernate.testing.orm.junit.Setting; import org.junit.jupiter.api.Test; +import java.time.Instant; import java.time.OffsetDateTime; import java.time.ZoneId; import java.time.ZoneOffset; @@ -37,17 +38,19 @@ public class PassThruZonedTest { }); scope.inSession( s-> { Zoned z = s.find(Zoned.class, id); + ZoneId systemZone = ZoneId.systemDefault(); + ZoneOffset systemOffset = systemZone.getRules().getOffset( Instant.now() ); if ( scope.getSessionFactory().getJdbcServices().getDialect() instanceof SybaseDialect) { // Sybase with jTDS driver has 1/300th sec precision assertEquals( nowZoned.toInstant().truncatedTo(ChronoUnit.SECONDS), z.zonedDateTime.toInstant().truncatedTo(ChronoUnit.SECONDS)); assertEquals( nowOffset.toInstant().truncatedTo(ChronoUnit.SECONDS), z.offsetDateTime.toInstant().truncatedTo(ChronoUnit.SECONDS)); } else { - assertEquals( nowZoned.toInstant(), z.zonedDateTime.toInstant() ); - assertEquals( nowOffset.toInstant(), z.offsetDateTime.toInstant() ); + assertEquals( nowZoned.withZoneSameInstant(systemZone), z.zonedDateTime ); + assertEquals( nowOffset.withOffsetSameInstant(systemOffset), z.offsetDateTime ); } - assertEquals( ZoneId.systemDefault(), z.zonedDateTime.getZone() ); - assertEquals( ZoneOffset.systemDefault().normalized(), z.offsetDateTime.getOffset().normalized() ); + assertEquals( systemZone, z.zonedDateTime.getZone() ); + assertEquals( systemOffset, z.offsetDateTime.getOffset() ); }); } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/timezones/NormalizedZonedTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/timezones/UTCNormalizedZonedTest.java similarity index 95% rename from hibernate-core/src/test/java/org/hibernate/orm/test/timezones/NormalizedZonedTest.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/timezones/UTCNormalizedZonedTest.java index 7edbecec0e..3e0194f4d1 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/timezones/NormalizedZonedTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/timezones/UTCNormalizedZonedTest.java @@ -20,10 +20,10 @@ import java.time.temporal.ChronoUnit; import static org.junit.jupiter.api.Assertions.assertEquals; -@DomainModel(annotatedClasses = NormalizedZonedTest.Zoned.class) +@DomainModel(annotatedClasses = UTCNormalizedZonedTest.Zoned.class) @SessionFactory @ServiceRegistry(settings = @Setting(name = AvailableSettings.TIMEZONE_DEFAULT_STORAGE, value = "NORMALIZE_UTC")) -public class NormalizedZonedTest { +public class UTCNormalizedZonedTest { @Test void test(SessionFactoryScope scope) { ZonedDateTime nowZoned = ZonedDateTime.now().withZoneSameInstant( ZoneId.of("CET") );