Skip to content

Commit

Permalink
Fix age-old timestamp bug
Browse files Browse the repository at this point in the history
  • Loading branch information
kubukoz committed Jul 11, 2022
1 parent de76007 commit 24f19ca
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 9 deletions.
7 changes: 5 additions & 2 deletions core/src/main/scala/playground/QueryCompiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,11 @@ object QueryCompiler extends SchemaVisitor[PartialCompiler] {
// the actual serialization format will be used by the client when we eventually use it in the Runner.
val format = TimestampFormat.DATE_TIME

Timestamp
.parse(s.value, format)
TimestampPlatform
.fixupTimestamp(
Timestamp
.parse(s.value, format)
)
.toRightIor(
CompilationError(
InvalidTimestampFormat(format),
Expand Down
16 changes: 16 additions & 0 deletions core/src/main/scalajs/playground/TimestampPlatform.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package playground

import smithy4s.Timestamp
import cats.implicits._

// js
object TimestampPlatform {

// Workaround for smithy4s 0.13.x bug
def fixupTimestamp(opt: Option[Timestamp]): Option[Timestamp] =
opt match {
case Some(s) if Either.catchNonFatal(s.toString()).isRight => Some(s)
case _ => None
}

}
6 changes: 6 additions & 0 deletions core/src/main/scalajvm/playground/TimestampPlatform.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package playground

// jvm
object TimestampPlatform {
def fixupTimestamp[T](t: T): T = t
}
11 changes: 4 additions & 7 deletions core/src/test/scala/playground/smithyql/CompilationTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,11 @@ object CompilationTests extends SimpleIOSuite with Checkers {

// todo: timestamp parsing always passes on JS but does something weird.
// this is fixed in smithy4s 0.14.0
if (Platform.isJVM)
assert(
result == Ior.leftNec(
CompilationErrorDetails.InvalidTimestampFormat(TimestampFormat.DATE_TIME)
)
assert(
result == Ior.leftNec(
CompilationErrorDetails.InvalidTimestampFormat(TimestampFormat.DATE_TIME)
)
else
assert(result.toEither.isRight)
)
}

pureTest("uuid - OK") {
Expand Down

0 comments on commit 24f19ca

Please sign in to comment.