Skip to content

Commit

Permalink
fix: Add missing nano part when encoding timestamp to document
Browse files Browse the repository at this point in the history
  • Loading branch information
ghostbuster91 committed Aug 30, 2024
1 parent d4edb32 commit e0302bc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions modules/bootstrapped/test/src/smithy4s/DocumentSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,22 @@ class DocumentSpec() extends FunSuite {
)
}

test("Document encoder - timestamp epoch seconds with nanos") {
val timestampWithNanos = Timestamp(1716459630L, 5000000)
val result = Document.Encoder
.withExplicitDefaultsEncoding(false)
.fromSchema(TimestampOperationInput.schema)
.encode(TimestampOperationInput(timestampWithNanos, timestampWithNanos, timestampWithNanos))
expect.same(
Document.obj(
"httpDate" -> Document.fromString("Thu, 23 May 2024 10:20:30.005 GMT"),
"dateTime" -> Document.fromString("2024-05-23T10:20:30.005Z"),
"epochSeconds" -> Document.fromBigDecimal(BigDecimal("1716459630.500000"))
),
result
)
}

test("Document decoder - timestamp defaults") {
val doc = Document.obj()
val result = Document.Decoder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class DocumentEncoderSchemaVisitor(
.getOrElse(TimestampFormat.EPOCH_SECONDS) match {
case DATE_TIME => ts => DString(ts.format(DATE_TIME))
case HTTP_DATE => ts => DString(ts.format(HTTP_DATE))
case EPOCH_SECONDS => ts => DNumber(BigDecimal(ts.epochSecond))
case EPOCH_SECONDS => ts => DNumber(BigDecimal(s"${ts.epochSecond}.${ts.nano}"))
}
case PDocument => from(identity)
case PFloat => from(float => DNumber(BigDecimal(float.toDouble)))
Expand Down

0 comments on commit e0302bc

Please sign in to comment.