Skip to content

Commit

Permalink
Merge pull request #624 from commercetools/fix-instant-parser-offset-…
Browse files Browse the repository at this point in the history
…with-colon

[FIX] Instant Parser
  • Loading branch information
nolledge authored Oct 25, 2024
2 parents 9cfff44 + f9db447 commit c9c906a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
4 changes: 3 additions & 1 deletion json/json-core/src/main/scala/io/sphere/json/FromJSON.scala
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,10 @@ object FromJSON extends FromJSONInstances {
.appendPattern("'T'[HH[:mm[:ss]]]")
.appendFraction(time.temporal.ChronoField.NANO_OF_SECOND, 0, 9, true)
.optionalStart()
.appendOffset("+HHmm", "Z")
.appendOffset("+HH:MM", "Z")
.optionalEnd()
.optionalStart()
.appendOffset("+HHmm", "Z")
.optionalEnd()
.parseDefaulting(time.temporal.ChronoField.MONTH_OF_YEAR, 1L)
.parseDefaulting(time.temporal.ChronoField.DAY_OF_MONTH, 1L)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,22 @@ class DateTimeParsingSpec extends AnyWordSpec with Matchers {
Instant.parse("2004-06-09T12:24:48.501Z"))
}

"accept a year month day with hour, minute, second, and an offset containing a colon" in {
javaInstantReader.read(JString("2004-06-09T12:24:48+08:00")) shouldBe Valid(
Instant.parse("2004-06-09T04:24:48Z"))
}
"accept a year month day with hour, minute, second, and an offset of zero containing a colon" in {
javaInstantReader.read(JString("2004-06-09T12:24:48+00:00")) shouldBe Valid(
Instant.parse("2004-06-09T12:24:48Z"))
}
"accept a year month day with hour, minute, second, and a negative colon offset" in {
javaInstantReader.read(JString("2004-06-09T12:24:48-08:00")) shouldBe Valid(
Instant.parse("2004-06-09T20:24:48Z"))
}
"accept a year month day with hour, minute, second, and an offset of hours only" in {
javaInstantReader.read(JString("2004-06-09T12:24:48+00")) shouldBe Valid(
Instant.parse("2004-06-09T12:24:48Z"))
}
}

}

0 comments on commit c9c906a

Please sign in to comment.