Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fill the missing date/time related decoding in ReadExecutor #287

Merged
merged 5 commits into from
Nov 25, 2020
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions jdbc/src/main/scala/zio/sql/jdbc.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package zio.sql

import java.sql._
import java.io.IOException
import java.time.{ ZoneId, ZoneOffset }
import java.time.{ OffsetDateTime, OffsetTime, ZoneId, ZoneOffset, ZonedDateTime }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove unused import

[error] /home/circleci/project/jdbc/src/main/scala/zio/sql/jdbc.scala:5:68: Unused import
[error] import java.time.{ OffsetDateTime, OffsetTime, ZoneId, ZoneOffset, ZonedDateTime }
[error]                                                                    ^


import zio.{ Chunk, Has, IO, Managed, ZIO, ZLayer, ZManaged }
import zio.blocking.Blocking
import zio.stream.{ Stream, ZStream }
Expand Down Expand Up @@ -184,8 +185,21 @@ 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))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to https://jdbc.postgresql.org/documentation/head/java8-date-time.html, "OffsetDateTime instances will have be in UTC (have offset 0). This is because the backend stores them as UTC" - can you please change this to be UTC instead of local time?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes for sure. Thank you for the feedback. See my latest commit.

)
case TOffsetTime =>
tryDecode[OffsetTime](
column
.fold(resultSet.getTimestamp(_), resultSet.getTimestamp(_))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we need resultSet.getTime for this - I'm not sure what calling getTimestamp on a time column would do.

.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 =>
Expand Down