Skip to content

Commit e259a17

Browse files
committed
Now able to avoid duplication in InstantConverter and LocalDateTimeConverter
1 parent 8f0b6d0 commit e259a17

2 files changed

Lines changed: 3 additions & 7 deletions

File tree

JSqlServerBulkInsert/src/main/java/de/bytefish/jsqlserverbulkinsert/converters/InstantConverter.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@ public class InstantConverter extends BaseConverter<Instant> {
77

88
@Override
99
public Object internalConvert(Instant value) {
10-
11-
if (value == null) {
12-
return null;
13-
}
14-
1510
Timestamp castedResult = new Timestamp(value.toEpochMilli());
1611

1712
// Round to the nearest 100 nanoseconds, the precision that SQL server can handle:

JSqlServerBulkInsert/src/main/java/de/bytefish/jsqlserverbulkinsert/converters/LocalDateTimeConverter.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
import java.time.LocalDate;
55
import java.time.LocalDateTime;
66
import java.time.OffsetDateTime;
7+
import java.time.ZoneOffset;
78

89
public class LocalDateTimeConverter extends BaseConverter<LocalDateTime> {
10+
static ZoneOffset zoneOffset = OffsetDateTime.now().getOffset();
911
@Override
1012
public Object internalConvert(LocalDateTime value) {
11-
12-
long epochSeconds = value.toEpochSecond(OffsetDateTime.now().getOffset());
13+
long epochSeconds = value.toEpochSecond(zoneOffset);
1314

1415
// Convert to milliseconds to create the Timestamp:
1516
Timestamp castedResult = new Timestamp(epochSeconds * 1000);

0 commit comments

Comments
 (0)