@@ -121,7 +121,9 @@ public void testEncodeDate(TestContext ctx) {
121
121
@ Test
122
122
@ Repeat (100 )
123
123
public void testEncodeTime (TestContext ctx ) {
124
- LocalTime now = LocalTime .now ();
124
+ // Make sure the number of significant digits matches the column precision
125
+ int nanoOfSecond = 1_000 * ThreadLocalRandom .current ().nextInt (1_000_000 );
126
+ LocalTime now = LocalTime .now ().withNano (nanoOfSecond );
125
127
testPreparedQueryEncodeGeneric (ctx , "not_nullable_datatype" , "test_time" , now , row -> {
126
128
ColumnChecker .checkColumn (0 , "test_time" )
127
129
.returns (Tuple ::getValue , Row ::getValue , now )
@@ -180,7 +182,9 @@ public void testEncodeDateTime(TestContext ctx) {
180
182
@ Test
181
183
@ Repeat (100 )
182
184
public void testEncodeDateTime2 (TestContext ctx ) {
183
- LocalDateTime now = LocalDateTime .now ();
185
+ // Make sure the number of significant digits matches the column precision
186
+ int nanoOfSecond = 100 * ThreadLocalRandom .current ().nextInt (10_000_000 );
187
+ LocalDateTime now = LocalDateTime .now ().withNano (nanoOfSecond );
184
188
testPreparedQueryEncodeGeneric (ctx , "not_nullable_datatype" , "test_datetime2" , now , row -> {
185
189
ColumnChecker .checkColumn (0 , "test_datetime2" )
186
190
.returns (Tuple ::getValue , Row ::getValue , now )
@@ -195,14 +199,7 @@ public void testEncodeDateTime2(TestContext ctx) {
195
199
@ Test
196
200
@ Repeat (100 )
197
201
public void testEncodeOffsetDateTime (TestContext ctx ) {
198
- /*
199
- Starting from Java 11, LocalDateTime.now() can have microseconds precision.
200
- But the test database defines the test_datetimeoffset column with scale of 5.
201
-
202
- Therefore, in order to get consistent behavior between Java 8 and Java 11,
203
- we erase the nanoOfSecond value obtained from the clock with a random number
204
- which has at most tens of microseconds precision.
205
- */
202
+ // Make sure the number of significant digits matches the column precision
206
203
int nanoOfSecond = ThreadLocalRandom .current ().nextInt (100_000 ) * 10_000 ;
207
204
OffsetDateTime now = LocalDateTime .now ().withNano (nanoOfSecond )
208
205
.atOffset (ZoneOffset .ofHoursMinutes (-3 , -15 ));
0 commit comments