24
24
import io .r2dbc .postgresql .util .Assert ;
25
25
import reactor .util .annotation .Nullable ;
26
26
27
- import java .time .Instant ;
27
+ import java .time .LocalDateTime ;
28
+ import java .time .ZoneId ;
28
29
import java .util .Date ;
29
30
30
31
final class DateCodec extends AbstractCodec <Date > {
31
32
32
- private final InstantCodec delegate ;
33
+ private final LocalDateTimeCodec delegate ;
33
34
34
35
DateCodec (ByteBufAllocator byteBufAllocator ) {
35
36
super (Date .class );
36
37
37
38
Assert .requireNonNull (byteBufAllocator , "byteBufAllocator must not be null" );
38
- this .delegate = new InstantCodec (byteBufAllocator );
39
+ this .delegate = new LocalDateTimeCodec (byteBufAllocator );
39
40
}
40
41
41
42
@ Override
@@ -55,14 +56,15 @@ boolean doCanDecode(PostgresqlObjectId type, Format format) {
55
56
Date doDecode (ByteBuf buffer , PostgresqlObjectId dataType , @ Nullable Format format , @ Nullable Class <? extends Date > type ) {
56
57
Assert .requireNonNull (buffer , "byteBuf must not be null" );
57
58
58
- return Date .from (this .delegate .doDecode (buffer , dataType , format , Instant .class ));
59
+ LocalDateTime intermediary = this .delegate .doDecode (buffer , dataType , format , LocalDateTime .class );
60
+ return Date .from (intermediary .atZone (ZoneId .systemDefault ()).toInstant ());
59
61
}
60
62
61
63
@ Override
62
64
Parameter doEncode (Date value ) {
63
65
Assert .requireNonNull (value , "value must not be null" );
64
66
65
- return this .delegate .doEncode (value .toInstant ());
67
+ return this .delegate .doEncode (value .toInstant (). atZone ( ZoneId . systemDefault ()). toLocalDateTime () );
66
68
}
67
69
68
70
}
0 commit comments