Skip to content

Commit

Permalink
Version that works for both JS and Native
Browse files Browse the repository at this point in the history
  • Loading branch information
msosnicki committed Dec 11, 2024
1 parent 9b1201f commit 7f20f9b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,16 @@ class DocumentEncoderSchemaVisitor(
case EPOCH_SECONDS =>
ts =>
DNumber(
BigDecimal(ts.epochSecond) + BigDecimal(
ts.nano * 1 / 1000000000.0
)
.underlying()
.stripTrailingZeros()
BigDecimal({
val es = java.math.BigDecimal.valueOf(ts.epochSecond)
if (ts.nano == 0) es
else
es.add(
java.math.BigDecimal
.valueOf(ts.nano.toLong, 9)
.stripTrailingZeros
)
})
)
}
case PDocument => from(identity)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,11 +394,14 @@ private[smithy4s] class SchemaVisitorJCodec(
}

def encodeValue(x: Timestamp, out: JsonWriter): Unit = {
out.writeVal(
BigDecimal(x.epochSecond) + BigDecimal(x.nano * 1 / 1000000000.0)
.underlying()
.stripTrailingZeros()
)
out.writeVal(BigDecimal({
val es = java.math.BigDecimal.valueOf(x.epochSecond)
if (x.nano == 0) es
else
es.add(
java.math.BigDecimal.valueOf(x.nano.toLong, 9).stripTrailingZeros
)
}))
}

def decodeKey(in: JsonReader): Timestamp = {
Expand Down

0 comments on commit 7f20f9b

Please sign in to comment.