Skip to content

Commit 1852777

Browse files
committed
Revise temporal rendering and parsing in text mode.
We now revised text-encoded temporal value parsing to accomodate for proper timezone and ERA indicators. Also, we now translate infinity and -infinity values into the corresponding MAX (e.g. LocalDateTime.MAX) and MIN values. [resolves #578] Signed-off-by: Mark Paluch <[email protected]>
1 parent b6ebc1c commit 1852777

22 files changed

+809
-158
lines changed

src/main/java/io/r2dbc/postgresql/codec/AbstractTemporalCodec.java

+5-7
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,10 @@
2424
import reactor.util.annotation.Nullable;
2525

2626
import java.time.LocalDate;
27-
import java.time.LocalDateTime;
2827
import java.time.LocalTime;
2928
import java.time.OffsetDateTime;
3029
import java.time.OffsetTime;
3130
import java.time.ZoneOffset;
32-
import java.time.ZonedDateTime;
3331
import java.time.temporal.Temporal;
3432
import java.util.EnumSet;
3533
import java.util.Set;
@@ -118,28 +116,28 @@ private Temporal decodeTemporal(ByteBuf buffer, PostgresqlObjectId dataType, @Nu
118116
return EpochTime.fromLong(buffer.readLong()).toLocalDateTime();
119117
}
120118

121-
return PostgresqlDateTimeFormatter.parse(ByteBufUtils.decode(buffer), LocalDateTime::from);
119+
return PostgresqlDateTimeFormatter.parseLocalDateTime(ByteBufUtils.decode(buffer));
122120
case DATE:
123121
case DATE_ARRAY:
124122
if (FORMAT_BINARY == format) {
125123
return LocalDate.ofEpochDay(EpochTime.fromInt(buffer.readInt()).getJavaDays());
126124
}
127125

128-
return LocalDate.parse(ByteBufUtils.decode(buffer));
126+
return PostgresqlDateTimeFormatter.parseLocalDate(ByteBufUtils.decode(buffer));
129127
case TIME:
130128
case TIME_ARRAY:
131129
if (FORMAT_BINARY == format) {
132130
return LocalTime.ofNanoOfDay(buffer.readLong() * 1000);
133131
}
134132

135-
return LocalTime.parse(ByteBufUtils.decode(buffer));
133+
return PostgresqlTimeFormatter.parseLocalTime(ByteBufUtils.decode(buffer));
136134
case TIMESTAMPTZ:
137135
case TIMESTAMPTZ_ARRAY:
138136
if (FORMAT_BINARY == format) {
139137
return EpochTime.fromLong(buffer.readLong()).toInstant().atOffset(OffsetDateTime.now().getOffset());
140138
}
141139

142-
return PostgresqlDateTimeFormatter.parse(ByteBufUtils.decode(buffer), ZonedDateTime::from);
140+
return PostgresqlDateTimeFormatter.parseOffsetDateTime(ByteBufUtils.decode(buffer));
143141
case TIMETZ:
144142
case TIMETZ_ARRAY:
145143
if (FORMAT_BINARY == format) {
@@ -148,7 +146,7 @@ private Temporal decodeTemporal(ByteBuf buffer, PostgresqlObjectId dataType, @Nu
148146
return OffsetTime.of(LocalTime.ofNanoOfDay(timeNano), ZoneOffset.ofTotalSeconds(offsetSec));
149147
}
150148

151-
return PostgresqlTimeFormatter.parse(ByteBufUtils.decode(buffer), OffsetTime::from);
149+
return PostgresqlTimeFormatter.parseOffsetTime(ByteBufUtils.decode(buffer));
152150
}
153151

154152
throw new UnsupportedOperationException(String.format("Cannot decode value for type %s, format %s", dataType, format));

src/main/java/io/r2dbc/postgresql/codec/InstantCodec.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ final class InstantCodec extends AbstractTemporalCodec<Instant> {
3737
private final Supplier<ZoneId> zoneIdSupplier;
3838

3939
InstantCodec(ByteBufAllocator byteBufAllocator, Supplier<ZoneId> zoneIdSupplier) {
40-
super(Instant.class, byteBufAllocator, TIMESTAMPTZ, TIMESTAMPTZ_ARRAY, Instant::toString);
40+
super(Instant.class, byteBufAllocator, TIMESTAMPTZ, TIMESTAMPTZ_ARRAY, it -> PostgresqlDateTimeFormatter.toString(it));
4141
this.zoneIdSupplier = zoneIdSupplier;
4242
}
4343

src/main/java/io/r2dbc/postgresql/codec/LocalDateCodec.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
final class LocalDateCodec extends AbstractTemporalCodec<LocalDate> {
3434

3535
LocalDateCodec(ByteBufAllocator byteBufAllocator) {
36-
super(LocalDate.class, byteBufAllocator, DATE, DATE_ARRAY, LocalDate::toString);
36+
super(LocalDate.class, byteBufAllocator, DATE, DATE_ARRAY, PostgresqlDateTimeFormatter::toString);
3737
}
3838

3939
@Override

src/main/java/io/r2dbc/postgresql/codec/LocalDateTimeCodec.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ final class LocalDateTimeCodec extends AbstractTemporalCodec<LocalDateTime> {
3737
private final Supplier<ZoneId> zoneIdSupplier;
3838

3939
LocalDateTimeCodec(ByteBufAllocator byteBufAllocator, Supplier<ZoneId> zoneIdSupplier) {
40-
super(LocalDateTime.class, byteBufAllocator, TIMESTAMP, TIMESTAMP_ARRAY, LocalDateTime::toString);
40+
super(LocalDateTime.class, byteBufAllocator, TIMESTAMP, TIMESTAMP_ARRAY, PostgresqlDateTimeFormatter::toString);
4141
this.zoneIdSupplier = Assert.requireNonNull(zoneIdSupplier, "zoneIdSupplier must not be null");
4242
}
4343

src/main/java/io/r2dbc/postgresql/codec/LocalTimeCodec.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
final class LocalTimeCodec extends AbstractTemporalCodec<LocalTime> {
3434

3535
LocalTimeCodec(ByteBufAllocator byteBufAllocator) {
36-
super(LocalTime.class, byteBufAllocator, TIME, TIME_ARRAY, LocalTime::toString);
36+
super(LocalTime.class, byteBufAllocator, TIME, TIME_ARRAY, PostgresqlTimeFormatter::toString);
3737
}
3838

3939
@Override

src/main/java/io/r2dbc/postgresql/codec/OffsetDateTimeCodec.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
final class OffsetDateTimeCodec extends AbstractTemporalCodec<OffsetDateTime> {
3131

3232
OffsetDateTimeCodec(ByteBufAllocator byteBufAllocator) {
33-
super(OffsetDateTime.class, byteBufAllocator, TIMESTAMPTZ, TIMESTAMPTZ_ARRAY, OffsetDateTime::toString);
33+
super(OffsetDateTime.class, byteBufAllocator, TIMESTAMPTZ, TIMESTAMPTZ_ARRAY, PostgresqlDateTimeFormatter::toString);
3434
}
3535

3636
@Override

src/main/java/io/r2dbc/postgresql/codec/OffsetTimeCodec.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
public class OffsetTimeCodec extends AbstractTemporalCodec<OffsetTime> {
3030

3131
OffsetTimeCodec(ByteBufAllocator byteBufAllocator) {
32-
super(OffsetTime.class, byteBufAllocator, TIMETZ, TIMETZ_ARRAY, OffsetTime::toString);
32+
super(OffsetTime.class, byteBufAllocator, TIMETZ, TIMETZ_ARRAY, PostgresqlTimeFormatter::toString);
3333
}
3434

3535
@Override

0 commit comments

Comments
 (0)