9
9
import java .time .ZoneId ;
10
10
import java .time .ZoneOffset ;
11
11
import java .time .ZonedDateTime ;
12
+ import java .time .temporal .ChronoUnit ;
12
13
import java .util .Collection ;
13
14
import java .util .List ;
14
15
29
30
import static org .hibernate .cfg .AvailableSettings .TIMEZONE_DEFAULT_STORAGE ;
30
31
import static org .hibernate .reactive .containers .DatabaseConfiguration .DBType .DB2 ;
31
32
import static org .hibernate .reactive .testing .ReactiveAssertions .assertWithTruncationThat ;
32
- import static org .hibernate .type .descriptor .DateTimeUtils .roundToDefaultPrecision ;
33
+ import static org .hibernate .type .descriptor .DateTimeUtils .adjustToDefaultPrecision ;
33
34
35
+ /**
36
+ * Test adapted from {@link org.hibernate.orm.test.timezones.ColumnZonedTest}
37
+ */
34
38
@ Timeout (value = 10 , timeUnit = MINUTES )
35
39
@ DisabledFor (value = DB2 , reason = "java.sql.SQLException: An error occurred with a DB2 operation, SQLCODE=-180 SQLSTATE=22007" )
36
40
public class ColumnZonedTest extends BaseReactiveTest {
@@ -48,8 +52,16 @@ protected void setProperties(Configuration configuration) {
48
52
49
53
@ Test
50
54
public void test (VertxTestContext context ) {
51
- ZonedDateTime nowZoned = ZonedDateTime .now ().withZoneSameInstant ( ZoneId .of ( "CET" ) );
52
- OffsetDateTime nowOffset = OffsetDateTime .now ().withOffsetSameInstant ( ZoneOffset .ofHours ( 3 ) );
55
+ final ZonedDateTime nowZoned ;
56
+ final OffsetDateTime nowOffset ;
57
+ if ( getDialect ().getDefaultTimestampPrecision () == 6 ) {
58
+ nowZoned = ZonedDateTime .now ().withZoneSameInstant ( ZoneId .of ("CET" ) ).truncatedTo ( ChronoUnit .MICROS );
59
+ nowOffset = OffsetDateTime .now ().withOffsetSameInstant ( ZoneOffset .ofHours (3 ) ).truncatedTo ( ChronoUnit .MICROS );
60
+ }
61
+ else {
62
+ nowZoned = ZonedDateTime .now ().withZoneSameInstant ( ZoneId .of ("CET" ) );
63
+ nowOffset = OffsetDateTime .now ().withOffsetSameInstant ( ZoneOffset .ofHours (3 ) );
64
+ }
53
65
test ( context , getSessionFactory ()
54
66
.withTransaction ( s -> {
55
67
Zoned z = new Zoned ();
@@ -60,10 +72,10 @@ public void test(VertxTestContext context) {
60
72
.thenCompose ( zid -> openSession ()
61
73
.thenCompose ( s -> s .find ( Zoned .class , zid )
62
74
.thenAccept ( z -> {
63
- assertWithTruncationThat ( roundToDefaultPrecision ( z .zonedDateTime .toInstant (), getDialect () ) )
64
- .isEqualTo ( roundToDefaultPrecision ( nowZoned .toInstant (), getDialect () ) );
65
- assertWithTruncationThat ( roundToDefaultPrecision ( z .offsetDateTime .toInstant (), getDialect () ) )
66
- .isEqualTo ( roundToDefaultPrecision ( nowOffset .toInstant (), getDialect () ) );
75
+ assertWithTruncationThat ( adjustToDefaultPrecision ( z .zonedDateTime .toInstant (), getDialect () ) )
76
+ .isEqualTo ( adjustToDefaultPrecision ( nowZoned .toInstant (), getDialect () ) );
77
+ assertWithTruncationThat ( adjustToDefaultPrecision ( z .offsetDateTime .toInstant (), getDialect () ) )
78
+ .isEqualTo ( adjustToDefaultPrecision ( nowOffset .toInstant (), getDialect () ) );
67
79
assertThat ( z .zonedDateTime .toOffsetDateTime ().getOffset () )
68
80
.isEqualTo ( nowZoned .toOffsetDateTime ().getOffset () );
69
81
assertThat ( z .offsetDateTime .getOffset () )
0 commit comments