File tree Expand file tree Collapse file tree 3 files changed +9
-35
lines changed
main/java/info/unterrainer/commons/rdbutils/converters
test/java/info/unterrainer/commons/rdbutils Expand file tree Collapse file tree 3 files changed +9
-35
lines changed Original file line number Diff line number Diff line change 11package info .unterrainer .commons .rdbutils .converters ;
22
33import java .sql .Timestamp ;
4- import java .time .Instant ;
54import java .time .LocalDateTime ;
6- import java .time .ZoneId ;
7- import java .time .ZonedDateTime ;
85import java .time .temporal .ChronoUnit ;
96
107import jakarta .persistence .AttributeConverter ;
118import jakarta .persistence .Converter ;
12- import info .unterrainer .commons .jreutils .DateUtils ;
139
1410@ Converter ()
1511public class LocalDateTimeConverter implements AttributeConverter <LocalDateTime , Timestamp > {
@@ -23,12 +19,10 @@ public Timestamp convertToDatabaseColumn(final LocalDateTime entityValue) {
2319 return timestamp ;
2420 }
2521
26- // FIXXXING
2722 @ Override
2823 public LocalDateTime convertToEntityAttribute (final Timestamp dbValue ) {
2924 if (dbValue == null )
3025 return null ;
31- LocalDateTime ldt = DateUtils .epochToUtcLocalDateTime (dbValue .getTime ());
32- return ldt .withNano (dbValue .getNanos ());
26+ return dbValue .toLocalDateTime ();
3327 }
3428}
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 44
55import java .sql .Timestamp ;
66import java .time .LocalDateTime ;
7+ import java .time .temporal .ChronoUnit ;
78
89import org .junit .jupiter .api .Test ;
910
@@ -18,14 +19,18 @@ public class LocalDateTimeConverterTests {
1819 public void conversionFromLocalDateTimeToTimestamp () {
1920 LocalDateTime d = DateUtils .nowUtc ();
2021 Timestamp ts = converter .convertToDatabaseColumn (d );
21- assertThat (DateUtils . utcLocalDateTimeToEpoch ( d )).isEqualTo (ts . getTime ( ));
22+ assertThat (ts . toLocalDateTime ( )).isEqualTo (d . truncatedTo ( ChronoUnit . MICROS ));
2223 }
2324
2425 @ Test
2526 public void conversionFromTimestampToLocalDateTime () {
26- Timestamp ts = new Timestamp (DateUtils .utcLocalDateTimeToEpoch (DateUtils .nowUtc ()));
27+ LocalDateTime now = DateUtils .nowUtc ();
28+ Timestamp ts = new Timestamp (DateUtils .utcLocalDateTimeToEpoch (now ));
2729 LocalDateTime d = converter .convertToEntityAttribute (ts );
2830
29- assertThat (ts .getTime ()).isEqualTo (DateUtils .utcLocalDateTimeToEpoch (d ));
31+ Timestamp timestamp = Timestamp .valueOf (d );
32+ timestamp .setNanos (d .truncatedTo (ChronoUnit .MICROS ).getNano ());
33+
34+ assertThat (d ).isEqualTo (ts .toLocalDateTime ());
3035 }
3136}
You can’t perform that action at this time.
0 commit comments