From a83438a6788978a756ddc94d6e52582c4c933602 Mon Sep 17 00:00:00 2001 From: LAURA CHAPMAN Date: Sat, 21 Nov 2020 10:40:18 -0500 Subject: [PATCH 1/3] Fill the missing date/time related decoding in ReadExecutor --- jdbc/src/main/scala/zio/sql/jdbc.scala | 28 +++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/jdbc/src/main/scala/zio/sql/jdbc.scala b/jdbc/src/main/scala/zio/sql/jdbc.scala index 73be39c16..d697cb9c5 100644 --- a/jdbc/src/main/scala/zio/sql/jdbc.scala +++ b/jdbc/src/main/scala/zio/sql/jdbc.scala @@ -1,9 +1,8 @@ package zio.sql import java.sql._ - import java.io.IOException - +import java.time.{ OffsetDateTime, OffsetTime, ZoneId, ZoneOffset, ZonedDateTime } import zio.{ Chunk, Has, IO, Managed, ZIO, ZLayer, ZManaged } import zio.blocking.Blocking import zio.stream.{ Stream, ZStream } @@ -185,15 +184,34 @@ trait Jdbc extends zio.sql.Sql { column.fold(resultSet.getTimestamp(_), resultSet.getTimestamp(_)).toLocalDateTime().toLocalTime() ) case TLong => tryDecode[Long](column.fold(resultSet.getLong(_), resultSet.getLong(_))) - case TOffsetDateTime => ??? - case TOffsetTime => ??? + case TOffsetDateTime => + tryDecode[OffsetDateTime]( + column + .fold(resultSet.getTimestamp(_), resultSet.getTimestamp(_)) + .toLocalDateTime() + .atOffset(ZoneOffset.of(ZoneId.systemDefault().getId)) + ) + case TOffsetTime => + tryDecode[OffsetTime]( + column + .fold(resultSet.getTimestamp(_), resultSet.getTimestamp(_)) + .toLocalDateTime() + .toLocalTime + .atOffset(ZoneOffset.of(ZoneId.systemDefault().getId)) + ) case TShort => tryDecode[Short](column.fold(resultSet.getShort(_), resultSet.getShort(_))) case TString => tryDecode[String](column.fold(resultSet.getString(_), resultSet.getString(_))) case TUUID => tryDecode[java.util.UUID]( java.util.UUID.fromString(column.fold(resultSet.getString(_), resultSet.getString(_))) ) - case TZonedDateTime => ??? + case TZonedDateTime => + tryDecode[ZonedDateTime]( + column + .fold(resultSet.getTimestamp(_), resultSet.getTimestamp(_)) + .toLocalDateTime() + .atZone(ZoneId.systemDefault()) + ) case TDialectSpecific(_) => ??? case t @ Nullable() => extractColumn(column, resultSet, t.typeTag, false).map(Option(_)) } From 0449a62788cdd76d5b049d687cce4552ecddb50d Mon Sep 17 00:00:00 2001 From: LAURA CHAPMAN Date: Wed, 25 Nov 2020 08:56:32 -0500 Subject: [PATCH 2/3] fix for Fill the missing date/time related decoding in ReadExecutor --- jdbc/src/main/scala/zio/sql/jdbc.scala | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/jdbc/src/main/scala/zio/sql/jdbc.scala b/jdbc/src/main/scala/zio/sql/jdbc.scala index 93d68af10..6481d35e0 100644 --- a/jdbc/src/main/scala/zio/sql/jdbc.scala +++ b/jdbc/src/main/scala/zio/sql/jdbc.scala @@ -190,15 +190,14 @@ trait Jdbc extends zio.sql.Sql { column .fold(resultSet.getTimestamp(_), resultSet.getTimestamp(_)) .toLocalDateTime() - .atOffset(ZoneOffset.of(ZoneId.systemDefault().getId)) + .atOffset(ZoneOffset.UTC) ) case TOffsetTime => tryDecode[OffsetTime]( column - .fold(resultSet.getTimestamp(_), resultSet.getTimestamp(_)) - .toLocalDateTime() + .fold(resultSet.getTime(_), resultSet.getTime(_)) .toLocalTime - .atOffset(ZoneOffset.of(ZoneId.systemDefault().getId)) + .atOffset(ZoneOffset.UTC) ) case TShort => tryDecode[Short](column.fold(resultSet.getShort(_), resultSet.getShort(_))) case TString => tryDecode[String](column.fold(resultSet.getString(_), resultSet.getString(_))) From 569101bdbce275ea78483d151297c0b418ef3658 Mon Sep 17 00:00:00 2001 From: LAURA CHAPMAN Date: Wed, 25 Nov 2020 14:01:30 -0500 Subject: [PATCH 3/3] remove unused import --- jdbc/src/main/scala/zio/sql/jdbc.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jdbc/src/main/scala/zio/sql/jdbc.scala b/jdbc/src/main/scala/zio/sql/jdbc.scala index 6481d35e0..f489de0ee 100644 --- a/jdbc/src/main/scala/zio/sql/jdbc.scala +++ b/jdbc/src/main/scala/zio/sql/jdbc.scala @@ -2,7 +2,7 @@ package zio.sql import java.sql._ import java.io.IOException -import java.time.{ OffsetDateTime, OffsetTime, ZoneId, ZoneOffset, ZonedDateTime } +import java.time.{ OffsetDateTime, OffsetTime, ZoneId, ZoneOffset } import zio.{ Chunk, Has, IO, Managed, ZIO, ZLayer, ZManaged } import zio.blocking.Blocking