Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example for parseInstant #1

Closed
ralfhecktor opened this issue Oct 28, 2015 · 3 comments
Closed

Example for parseInstant #1

ralfhecktor opened this issue Oct 28, 2015 · 3 comments
Assignees
Labels

Comments

@ralfhecktor
Copy link

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.

@sargue sargue self-assigned this Oct 28, 2015
@sargue sargue added the bug label Oct 28, 2015
@sargue
Copy link
Owner

sargue commented Oct 28, 2015

It is a bug, confirmed. I'm writing a test case and fixing it ASAP. Thanks for the report.

@ralfhecktor
Copy link
Author

Thank you! Looking forward using this feature :-)

@sargue
Copy link
Owner

sargue commented Oct 29, 2015

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 ParseInstantas 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.

@sargue sargue modified the milestone: 1.1.0 Oct 29, 2015
@sargue sargue closed this as completed in 6f5a042 Oct 29, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants