File tree Expand file tree Collapse file tree 4 files changed +43
-6
lines changed
main/java/info/unterrainer/commons
test/java/info/unterrainer/commons/rdbutils Expand file tree Collapse file tree 4 files changed +43
-6
lines changed Original file line number Diff line number Diff line change 10
10
11
11
<modelVersion >4.0.0</modelVersion >
12
12
<artifactId >rdb-utils</artifactId >
13
- <version >0.1.2 </version >
13
+ <version >0.1.3 </version >
14
14
<name >RdbUtils</name >
15
15
<packaging >jar</packaging >
16
16
17
17
<dependencies >
18
18
<dependency >
19
19
<groupId >info.unterrainer.commons</groupId >
20
20
<artifactId >jre-utils</artifactId >
21
- <version >0.1.2 </version >
21
+ <version >0.1.4 </version >
22
22
</dependency >
23
23
<dependency >
24
24
<groupId >javax.persistence</groupId >
Original file line number Diff line number Diff line change 2
2
3
3
public class Information {
4
4
public static final String name = "Parent-POM" ;
5
- public static final String buildTime = "2020-12-10T07:24:25Z " ;
6
- public static final String pomVersion = "0.1.2 " ;
5
+ public static final String buildTime = "2021-03-05T08:10:04Z " ;
6
+ public static final String pomVersion = "0.1.3 " ;
7
7
}
Original file line number Diff line number Diff line change 7
7
import javax .persistence .AttributeConverter ;
8
8
import javax .persistence .Converter ;
9
9
10
+ import info .unterrainer .commons .jreutils .DateUtils ;
11
+
10
12
@ Converter ()
11
13
public class LocalDateTimeConverter implements AttributeConverter <LocalDateTime , Timestamp > {
12
14
15
+ DateUtils u ;
16
+
13
17
@ Override
14
18
public Timestamp convertToDatabaseColumn (final LocalDateTime attribute ) {
15
- return attribute == null ? null : Timestamp .valueOf (attribute .truncatedTo (ChronoUnit .MICROS ));
19
+ return attribute == null ? null
20
+ : new Timestamp (DateUtils .utcLocalDateTimeToEpoch (attribute .truncatedTo (ChronoUnit .MICROS )));
16
21
}
17
22
18
23
@ Override
19
24
public LocalDateTime convertToEntityAttribute (final Timestamp dbData ) {
20
- return dbData == null ? null : dbData .toLocalDateTime ( );
25
+ return dbData == null ? null : DateUtils . epochToUtcLocalDateTime ( dbData .getTime () );
21
26
}
22
27
}
Original file line number Diff line number Diff line change
1
+ package info .unterrainer .commons .rdbutils ;
2
+
3
+ import static org .assertj .core .api .Assertions .assertThat ;
4
+
5
+ import java .sql .Timestamp ;
6
+ import java .time .LocalDateTime ;
7
+
8
+ import org .junit .jupiter .api .Test ;
9
+
10
+ import info .unterrainer .commons .jreutils .DateUtils ;
11
+ import info .unterrainer .commons .rdbutils .converters .LocalDateTimeConverter ;
12
+
13
+ public class LocalDateTimeConverterTests {
14
+
15
+ LocalDateTimeConverter converter = new LocalDateTimeConverter ();
16
+
17
+ @ Test
18
+ public void conversionFromLocalDateTimeToTimestamp () {
19
+ LocalDateTime d = DateUtils .nowUtc ();
20
+ Timestamp ts = converter .convertToDatabaseColumn (d );
21
+
22
+ assertThat (DateUtils .utcLocalDateTimeToEpoch (d )).isEqualTo (ts .getTime ());
23
+ }
24
+
25
+ @ Test
26
+ public void conversionFromTimestampToLocalDateTime () {
27
+ Timestamp ts = new Timestamp (DateUtils .utcLocalDateTimeToEpoch (DateUtils .nowUtc ()));
28
+ LocalDateTime d = converter .convertToEntityAttribute (ts );
29
+
30
+ assertThat (ts .getTime ()).isEqualTo (DateUtils .utcLocalDateTimeToEpoch (d ));
31
+ }
32
+ }
You can’t perform that action at this time.
0 commit comments