When using `java-time.api/formatter`: java.time.temporal.UnsupportedTemporalTypeException: Unsupported field: InstantSeconds
devurandom opened this issue · 2 comments
devurandom commented
(jt/instant (jt/formatter "YYYYMMdd'T'HHmmssX" {:resolver-style :lenient
:case :insensitive})
"20240611T131542Z")
; throws:
; java.time.temporal.UnsupportedTemporalTypeException: Unsupported field: InstantSeconds
; java.time.DateTimeException: Unable to obtain Instant from TemporalAccessor: {MonthOfYear=6, WeekBasedYear[WeekFields[SUNDAY,1]]=2024, DayOfMonth=11, OffsetSeconds=0},ISO resolved to 13:15:42 of type java.time.format.Parsed
; clojure.lang.ExceptionInfo: Conversion failedOn the other hand:
(jt/instant (-> (.toFormatter (doto (DateTimeFormatterBuilder.)
(.parseLenient)
(.parseCaseInsensitive)
(.appendValue ChronoField/YEAR 4)
(.appendValue ChronoField/MONTH_OF_YEAR 2)
(.appendValue ChronoField/DAY_OF_MONTH 2)
(.appendLiteral "T")
(.appendValue ChronoField/HOUR_OF_DAY 2)
(.appendValue ChronoField/MINUTE_OF_HOUR 2)
(.appendValue ChronoField/SECOND_OF_MINUTE 2)
(.appendOffset "+HHMMss" "Z")))
(.withZone (ZoneId/of "UTC")))
"20240611T131542Z")
;=> #object[java.time.Instant 0x52b9aba9 "2024-06-11T13:15:42Z"]I would have expected both formatters to be (more or less) equivalent.
(My aim is to build a formatter and parser for the ISO 8601 "basic" format, as opposed to the "extended" format containing dashes and colons. All values need to be in the UTC timezone.)
frenchy64 commented
Thanks for the report. Is this the smallest failing case?
devurandom commented
Thanks for the report. Is this the smallest failing case?
That would be:
user=> (jt/instant (jt/formatter "ss" {:resolver-style :lenient :case :insensitive}) "42")
Execution error (UnsupportedTemporalTypeException) at java.time.format.Parsed/getLong (Parsed.java:215).
Unsupported field: InstantSeconds