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 1
1
package info .unterrainer .commons .rdbutils .converters ;
2
2
3
3
import java .sql .Timestamp ;
4
- import java .time .Instant ;
5
4
import java .time .LocalDateTime ;
6
- import java .time .ZoneId ;
7
- import java .time .ZonedDateTime ;
8
5
import java .time .temporal .ChronoUnit ;
9
6
10
7
import jakarta .persistence .AttributeConverter ;
11
8
import jakarta .persistence .Converter ;
12
- import info .unterrainer .commons .jreutils .DateUtils ;
13
9
14
10
@ Converter ()
15
11
public class LocalDateTimeConverter implements AttributeConverter <LocalDateTime , Timestamp > {
@@ -23,12 +19,10 @@ public Timestamp convertToDatabaseColumn(final LocalDateTime entityValue) {
23
19
return timestamp ;
24
20
}
25
21
26
- // FIXXXING
27
22
@ Override
28
23
public LocalDateTime convertToEntityAttribute (final Timestamp dbValue ) {
29
24
if (dbValue == null )
30
25
return null ;
31
- LocalDateTime ldt = DateUtils .epochToUtcLocalDateTime (dbValue .getTime ());
32
- return ldt .withNano (dbValue .getNanos ());
26
+ return dbValue .toLocalDateTime ();
33
27
}
34
28
}
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 4
4
5
5
import java .sql .Timestamp ;
6
6
import java .time .LocalDateTime ;
7
+ import java .time .temporal .ChronoUnit ;
7
8
8
9
import org .junit .jupiter .api .Test ;
9
10
@@ -18,14 +19,18 @@ public class LocalDateTimeConverterTests {
18
19
public void conversionFromLocalDateTimeToTimestamp () {
19
20
LocalDateTime d = DateUtils .nowUtc ();
20
21
Timestamp ts = converter .convertToDatabaseColumn (d );
21
- assertThat (DateUtils . utcLocalDateTimeToEpoch ( d )).isEqualTo (ts . getTime ( ));
22
+ assertThat (ts . toLocalDateTime ( )).isEqualTo (d . truncatedTo ( ChronoUnit . MICROS ));
22
23
}
23
24
24
25
@ Test
25
26
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 ));
27
29
LocalDateTime d = converter .convertToEntityAttribute (ts );
28
30
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 ());
30
35
}
31
36
}
You can’t perform that action at this time.
0 commit comments