legacy-jclouds icon indicating copy to clipboard operation
legacy-jclouds copied to clipboard

Unparsable date with a valid ISO 8601 date

Open gionn opened this issue 11 years ago • 3 comments

Hi,

I was trying the EC2 driver against the OpenNebula EC2 implementation, and I am getting errors parsing dates:

Caused by: java.text.ParseException: Unparseable date: "2013-02-14T17:53:20+0100" at java.text.DateFormat.parse(DateFormat.java:354) at org.jclouds.date.internal.SimpleDateFormatDateService.iso8601DateParse(SimpleDateFormatDateService.java:154)

The code I am using: https://gist.github.com/gionn/49ae4cd76f07ceac55f5 jclouds 1.5.8

AFAIK the date should be in ISO 8601 format (it is generated using the standard Ruby Time implementation)

Thanks.

gionn avatar Mar 18 '13 16:03 gionn

Hi Giovanni

It looks like the wrong parsing method is being called. iso8601DateParse is fine with the following input:

new SimpleDateFormatDateService().iso8601DateParse("2013-02-14T17:53:20.000+0100");

(note the milliseconds) but does indeed not like your input (accurate to seconds only). See iso8601SecondsSimpleDateFormat and iso8601SimpleDateFormat which underlie the behaviour.

The method that should presumably be called is iso8601SecondsDateParse. Or perhaps you can configure OpenNebula to return millis in its timestamps?

demobox avatar Mar 18 '13 16:03 demobox

I've tryed patching OpenNebula to return milliseconds too, and my code works as expected.

However, the actual DateTime specification states:

In the formats described in this specification the whole number of seconds ·may· be followed by decimal seconds to an arbitrary level of precision

It would be nicer if jclouds could accept time with or without milliseconds.

Thanks!

gionn avatar Mar 19 '13 22:03 gionn

I've tryed patching OpenNebula to return milliseconds too, and my code works as expected.

Glad to hear things work, at least. And given the specification you refer to, the correct patch is indeed probably not in OpenNebula, but in jclouds: replacing the call to iso8601DateParse (wherever it occurs the the case of the particular call you are making) with iso8601SecondsDateParse, or trying first one, then the other, or something similar.

@andrewgaul Thoughts on this one..?

demobox avatar Mar 20 '13 23:03 demobox