Skip to content

Commit

Permalink
Put the extracted Arrangement functions back to the tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Codegass committed Apr 15, 2024
1 parent a40e60d commit 3f0ad83
Showing 1 changed file with 9 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1875,8 +1875,11 @@ public void testNullValuesWithGetObject() throws Exception {

@Test
public void testGetLocalDateTimeTypesWithDefaultOffsetDateTimeConversion() throws Exception {
OffsetDateTime value = prepareOffsetDateTime();
LocalDateTime valueWithOffsetConversion = convertOffsetDateTimeToLocalDateTime(value);
OffsetDateTime value = OffsetDateTime.now().truncatedTo(ChronoUnit.MILLIS); // Linux has more precision than SQL Server
int offsetSeconds = value.getOffset().getTotalSeconds();
offsetSeconds += offsetSeconds < 0 ? 3600 : -3600;
value = value.withOffsetSameLocal(ZoneOffset.ofTotalSeconds(offsetSeconds));
LocalDateTime valueWithOffsetConversion = value.atZoneSameInstant(ZoneId.systemDefault()).toLocalDateTime();

try (SQLServerConnection conn = PrepUtil.getConnection(connectionString)) {
try (PreparedStatement stmt = conn.prepareStatement("SELECT ?")) {
Expand All @@ -1894,7 +1897,10 @@ public void testGetLocalDateTimeTypesWithDefaultOffsetDateTimeConversion() throw

@Test
public void testGetLocalDateTimeTypesWithIgnoreOffsetDateTimeConversion() throws Exception {
OffsetDateTime value = prepareOffsetDateTime();
OffsetDateTime value = OffsetDateTime.now().truncatedTo(ChronoUnit.MILLIS); // Linux has more precision than SQL Server
int offsetSeconds = value.getOffset().getTotalSeconds();
offsetSeconds += offsetSeconds < 0 ? 3600 : -3600;
value = value.withOffsetSameLocal(ZoneOffset.ofTotalSeconds(offsetSeconds));

try (SQLServerConnection conn = PrepUtil.getConnection(connectionString)) {
conn.setIgnoreOffsetOnDateTimeOffsetConversion(true);
Expand Down Expand Up @@ -1944,17 +1950,6 @@ public void testDateTimeOffsetValueOfOffsetDateTime() throws Exception {
assertEquals(expected, DateTimeOffset.valueOf(roundDown).getOffsetDateTime());
}

private OffsetDateTime prepareOffsetDateTime() {
OffsetDateTime value = OffsetDateTime.now().truncatedTo(ChronoUnit.MILLIS);
int offsetSeconds = value.getOffset().getTotalSeconds();
offsetSeconds += offsetSeconds < 0 ? 3600 : -3600;
return value.withOffsetSameLocal(ZoneOffset.ofTotalSeconds(offsetSeconds));
}

private LocalDateTime convertOffsetDateTimeToLocalDateTime(OffsetDateTime value) {
return value.atZoneSameInstant(ZoneId.systemDefault()).toLocalDateTime();
}

static LocalDateTime getUnstorableValue() throws Exception {
ZoneId systemTimezone = ZoneId.systemDefault();
Instant now = Instant.now();
Expand Down

0 comments on commit 3f0ad83

Please sign in to comment.