Closed ralfhecktor closed 9 years ago
It is a bug, confirmed. I'm writing a test case and fixing it ASAP. Thanks for the report.
Thank you! Looking forward using this feature :-)
Well, not that easy. I've never used the parse tags nor on this library or the original joda counterpart. It took me a while to focus. When I forked the library I converted the original ParseDateTime
tag into ParseInstant
as Instant
is the equivalent to joda's DateTime
. Never tried it.
The base problem is a design one, IMHO. In your example you are trying to parse a date which should be parsed to a LocalDate
, not to an Instant
. But the original library even uses the same example.
There are some StackOverflow questions relevant to this discussion:
If you look at java.time.format.DateTimeFormatter
there is a generic parse method which will return a TemporalAccessor
object which may or may not be useful to you.
I think the sensible approach is to split this tag into four. Yes, four tags.
parseLocalDate
parseLocalTime
parseLocalDateTime
parseInstant
Maybe even a fifth generic parse
. I resist because people will read fast and use it, then fail to understand why they can't work with the class. But it may be useful. Maybe calling it parseTemporalAccessor
would do the trick.
Hello,
I have some trouble getting the tag javatime:parseInstant running. Everything I tried results in
Caused by: java.time.format.DateTimeParseException: Text '2015-10-28' could not be parsed: Unable to obtain Instant from TemporalAccessor: {},ISO resolved to 2015-10-28 of type java.time.format.Parsed at java.time.format.DateTimeFormatter.createError(DateTimeFormatter.java:1920) ~[na:1.8.0_60] at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1855) ~[na:1.8.0_60] at net.sargue.time.jsptags.ParseInstantSupport.doEndTag(ParseInstantSupport.java:138) ~[java-time-jsptags-1.0.0.jar:1.0.0] at org.apache.jsp.WEB_002dINF.views.diary.overview_jsp._jspx_meth_jt_005fparseInstant_005f0(overview_jsp.java:207) ~[na:na] at org.apache.jsp.WEB_002dINF.views.diary.overview_jsp.access$1(overview_jsp.java:192) ~[na:na] at org.apache.jsp.WEB_002dINF.views.diary.overview_jsp$Helper.invoke2(overview_jsp.java:846) ~[na:na] at org.apache.jsp.WEB_002dINF.views.diary.overview_jsp$Helper.invoke(overview_jsp.java:1068) ~[na:na] at org.apache.jsp.tag.webtemplate_tag.doTag(webtemplate_tag.java:302) ~[na:na] at org.apache.jsp.WEB_002dINF.views.diary.overview_jsp._jspService(overview_jsp.java:153) ~[na:na] ... 60 common frames omitted
Caused by: java.time.DateTimeException: Unable to obtain Instant from TemporalAccessor: {},ISO resolved to 2015-10-28 of type java.time.format.Parsed at java.time.Instant.from(Instant.java:378) ~[na:1.8.0_60] at java.time.format.Parsed.query(Parsed.java:226) ~[na:1.8.0_60] at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1851) ~[na:1.8.0_60] ... 67 common frames omitted
Caused by: java.time.temporal.UnsupportedTemporalTypeException: Unsupported field: InstantSeconds at java.time.format.Parsed.getLong(Parsed.java:203) ~[na:1.8.0_60] at java.time.Instant.from(Instant.java:373) ~[na:1.8.0_60] ... 69 common frames omitted
. Could you maybe provide a running example e.g. for a String coded in ISO format?E.g.:
<javatime:parseInstant value="2015-10-28" pattern="yyyy-MM-dd" var="date" />
should store a LocaleDate in the variable date out of the provided string as far as I understand.