Skip to content

Commit

Permalink
add back the comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Codegass committed Apr 15, 2024
1 parent 3f0ad83 commit 93e95d8
Showing 1 changed file with 5 additions and 0 deletions.
Expand Up @@ -1875,6 +1875,7 @@ public void testNullValuesWithGetObject() throws Exception {

@Test
public void testGetLocalDateTimeTypesWithDefaultOffsetDateTimeConversion() throws Exception {
// test value needs to be in a time zone other than local
OffsetDateTime value = OffsetDateTime.now().truncatedTo(ChronoUnit.MILLIS); // Linux has more precision than SQL Server
int offsetSeconds = value.getOffset().getTotalSeconds();
offsetSeconds += offsetSeconds < 0 ? 3600 : -3600;
Expand All @@ -1887,6 +1888,7 @@ public void testGetLocalDateTimeTypesWithDefaultOffsetDateTimeConversion() throw
ResultSet rs = stmt.executeQuery();
rs.next();

// default behavior is to apply the time zone offset when converting DATETIMEOFFSET to local java.time types
assertEquals(value, rs.getObject(1, OffsetDateTime.class));
assertEquals(valueWithOffsetConversion, rs.getObject(1, LocalDateTime.class));
assertEquals(valueWithOffsetConversion.toLocalDate(), rs.getObject(1, LocalDate.class));
Expand All @@ -1903,13 +1905,16 @@ public void testGetLocalDateTimeTypesWithIgnoreOffsetDateTimeConversion() throws
value = value.withOffsetSameLocal(ZoneOffset.ofTotalSeconds(offsetSeconds));

try (SQLServerConnection conn = PrepUtil.getConnection(connectionString)) {

// change the behavior to be compatible with java.time conversion methods
conn.setIgnoreOffsetOnDateTimeOffsetConversion(true);

try (PreparedStatement stmt = conn.prepareStatement("SELECT ?")) {
stmt.setObject(1, value);
ResultSet rs = stmt.executeQuery();
rs.next();

// now the offset should be ignored instead of converting to local time zone
assertEquals(value, rs.getObject(1, OffsetDateTime.class));
assertEquals(value.toLocalDateTime(), rs.getObject(1, LocalDateTime.class));
assertEquals(value.toLocalDate(), rs.getObject(1, LocalDate.class));
Expand Down

0 comments on commit 93e95d8

Please sign in to comment.