Details
Description
There's no way to parse a single digit hour in the offset. Example:
2011-01-20 02:55:07.532941 -8:00
The spec needs to be modified to cover this case and the code enhanced to support it.
The only workaround is to parse the date/time separately, use a hand coded parser for the offset and combine the LocalDateTime with the hand parsed offset. Not an easy work around.
I have run across some occurrences of this though I can't say how common it is.
2011-01-20 02:55:07.532941 -8:00
The spec needs to be modified to cover this case and the code enhanced to support it.
The only workaround is to parse the date/time separately, use a hand coded parser for the offset and combine the LocalDateTime with the hand parsed offset. Not an easy work around.
I have run across some occurrences of this though I can't say how common it is.
Activity
Field | Original Value | New Value |
---|---|---|
Fix Version/s | 9 [ 14949 ] |
Assignee | Roger Riggs [ rriggs ] |
Status | New [ 10000 ] | Open [ 1 ] |
Assignee | Roger Riggs [ rriggs ] | Nadeesh Tv [ ntv ] |
Status | Open [ 1 ] | In Progress [ 3 ] |
Understanding | Cause Known [ 10000 ] |
Labels | jdk9-fc-request |
Summary | java.time.format.DateTimeFormatter cannot parse an offset with single digit hour. | java.time.format.DateTimeFormatter cannot parse an offset with single digit hour |
Labels | jdk9-fc-request | jdk9-fc-request jdk9-fc-yes |
Status | In Progress [ 3 ] | Resolved [ 5 ] |
Resolved In Build | team [ 17324 ] | |
Understanding | Cause Known [ 10000 ] | |
Resolution | Fixed [ 1 ] |
Resolved In Build | team [ 17324 ] | master [ 18256 ] |
Resolved In Build | master [ 18256 ] | b130 [ 17604 ] |
Labels | jdk9-fc-request jdk9-fc-yes | jdk9-fc-request jdk9-fc-yes jsr379-annex2-tbd |
Labels | jdk9-fc-request jdk9-fc-yes jsr379-annex2-tbd | jdk9-fc-request jdk9-fc-yes jsr379-annex1 |
Link | This issue csr of CCC-8066806 [ CCC-8066806 ] |
DateTimeFormatter f = new DateTimeFormatterBuilder().parseLenient().appendOffset("+HH:MM", "+00:00").toFormatter();
System.out.println(f.parse("+8:00", ZoneOffset::from));
Given the spec doesn't discuss strict vs lenient for appendOffset() one might be able to argue it as a bug.
Otherwise, in JDK 9, patterns will have to be added matching all the existing patterns for appendOffset() that print/parse a single digit, such as "+H:mm" (9 patterns in total).