11
11
import org .springframework .data .geo .Point ;
12
12
import org .springframework .data .redis .core .StringRedisTemplate ;
13
13
14
- import java .time .Instant ;
15
- import java .time .LocalDate ;
16
- import java .time .LocalDateTime ;
17
- import java .time .ZoneId ;
14
+ import java .time .*;
18
15
import java .time .temporal .ChronoUnit ;
19
16
import java .util .*;
20
17
35
32
36
33
private LocalDate localDate ;
37
34
private LocalDateTime localDateTime ;
35
+ private OffsetDateTime localOffsetDateTime ;
38
36
private Date date ;
39
37
private Point point ;
40
38
private Ulid ulid ;
@@ -50,6 +48,7 @@ public void cleanUp() {
50
48
51
49
localDate = LocalDate .now ();
52
50
localDateTime = LocalDateTime .now ();
51
+ localOffsetDateTime = OffsetDateTime .now ();
53
52
date = new Date ();
54
53
point = new Point (-111.83592170193586 ,33.62826024782707 );
55
54
ulid = UlidCreator .getMonotonicUlid ();
@@ -67,6 +66,7 @@ public void cleanUp() {
67
66
ks = KitchenSink .builder () //
68
67
.localDate (localDate ) //
69
68
.localDateTime (localDateTime ) //
69
+ .localOffsetDateTime (localOffsetDateTime ) //
70
70
.date (date ) //
71
71
.point (point ) //
72
72
.ulid (ulid ) //
@@ -77,6 +77,7 @@ public void cleanUp() {
77
77
ks1 = KitchenSink .builder () //
78
78
.localDate (localDate ) //
79
79
.localDateTime (localDateTime ) //
80
+ .localOffsetDateTime (localOffsetDateTime ) //
80
81
.date (date ) //
81
82
.point (point ) //
82
83
.ulid (ulid ) //
@@ -87,6 +88,7 @@ public void cleanUp() {
87
88
ks2 = KitchenSink .builder () //
88
89
.localDate (localDate ) //
89
90
.localDateTime (localDateTime ) //
91
+ .localOffsetDateTime (localOffsetDateTime ) //
90
92
.date (date ) //
91
93
.point (point ) //
92
94
.ulid (ulid ) //
@@ -98,6 +100,7 @@ public void cleanUp() {
98
100
ks3 = KitchenSink .builder () //
99
101
.localDate (localDate ) //
100
102
.localDateTime (localDateTime ) //
103
+ .localOffsetDateTime (localOffsetDateTime ) //
101
104
.date (date ) //
102
105
.point (point ) //
103
106
.ulid (ulid ) //
@@ -109,6 +112,7 @@ public void cleanUp() {
109
112
ks4 = KitchenSink .builder () //
110
113
.localDate (localDate ) //
111
114
.localDateTime (localDateTime ) //
115
+ .localOffsetDateTime (localOffsetDateTime ) //
112
116
.date (date ) //
113
117
.point (point ) //
114
118
.ulid (ulid ) //
@@ -134,6 +138,11 @@ void testHashSerialization() {
134
138
long localDateTimeInMillis = localDateTimeInstant .toEpochMilli ();
135
139
long rawLocalDateTime = Long .parseLong (Objects .requireNonNull (template .opsForHash ().get (key , "localDateTime" )).toString ());
136
140
141
+ // OffsetDateTime
142
+ Instant localOffsetDateTimeInstant = localOffsetDateTime .atZoneSameInstant (ZoneId .systemDefault ()).toInstant ();
143
+ long localOffsetDateTimeInMillis = localOffsetDateTimeInstant .toEpochMilli ();
144
+ long rawlocalOffsetDateTime = Long .parseLong (Objects .requireNonNull (template .opsForHash ().get (key , "localOffsetDateTime" )).toString ());
145
+
137
146
// Date
138
147
long dateInMillis = date .getTime ();
139
148
long rawDate = Long .parseLong (Objects .requireNonNull (template .opsForHash ().get (key , "date" )).toString ());
@@ -150,6 +159,7 @@ void testHashSerialization() {
150
159
151
160
assertThat (rawLocalDate ).isEqualTo (localDateAsUnixTS );
152
161
assertThat (rawLocalDateTime ).isEqualTo (localDateTimeInMillis );
162
+ assertThat (rawlocalOffsetDateTime ).isEqualTo (localOffsetDateTimeInMillis );
153
163
assertThat (rawDate ).isEqualTo (dateInMillis );
154
164
assertThat (rawPoint ).isEqualTo (redisGeo );
155
165
assertThat (rawUlid ).isEqualTo (ulid .toString ());
@@ -168,6 +178,7 @@ void testHashDeserialization() {
168
178
// NOTE: We lose nanosecond precision in order to store LocalDateTime as long in
169
179
// order to allow for RediSearch range queries
170
180
assertThat (fromDb .get ().getLocalDateTime ()).isEqualToIgnoringNanos (localDateTime );
181
+ assertThat (fromDb .get ().getLocalOffsetDateTime ()).isEqualToIgnoringNanos (localOffsetDateTime );
171
182
assertThat (fromDb .get ().getSetThings ()).isEqualTo (setThings );
172
183
assertThat (fromDb .get ().getListThings ()).isEqualTo (listThings );
173
184
}
0 commit comments