Difference between ValueTimestamp.parse(String) and newXMLGregorianCalendar(String)

209 views
Skip to first unread message

Steve

unread,
Nov 8, 2012, 8:23:40 AM11/8/12
to h2-da...@googlegroups.com
Hi!
My database contains a table which contains a java.sql.TIMESTAMP column. I found in the h2 databse source the ValueTimestamp.parse(String) function and so I tried to set the value of that column bei an ISO 8601 String "2012-11-08T12:40:11.156Z".
I was able to insert the row without any exception but in my opinion is the parsed value not correct.


org.h2.value.ValueTimestamp.parse("2012-11-08T12:40:11.156Z").getDate()
--> internal java.util.Date.fasttime: 1352329200000

DatatypeFactory.newInstance().newXMLGregorianCalendar("2012-11-08T12:40:11.156Z").toGregorianCalendar().getTime()
--> internal java.util.Date.fasttime: 1352378411156

Am I doing something wrong? Or will this bug fixed by the planned change  "Support date/time/timestamp as documented in http://en.wikipedia.org/wiki/ISO860"

Best Regards,
Steve



Thomas Mueller

unread,
Nov 8, 2012, 1:19:38 PM11/8/12
to h2-da...@googlegroups.com
Hi,

I didn't run it myself, but ValueTimestamp.getDate() returns a java.sql.Date (with the time set to 0) not a java.util.Date. What you might want to do is use getTimestamp() instead.

But why do you use internal classes of the database engine?

Regards,
Thomas






--
You received this message because you are subscribed to the Google Groups "H2 Database" group.
To view this discussion on the web visit https://groups.google.com/d/msg/h2-database/-/Mo89yOCxVsAJ.
To post to this group, send email to h2-da...@googlegroups.com.
To unsubscribe from this group, send email to h2-database...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/h2-database?hl=en.

Steve

unread,
Nov 9, 2012, 8:25:53 AM11/9/12
to h2-da...@googlegroups.com
Hi Thomas!
Yes you are right and I' wrong ;-) =>   It's java.sql.Date and not java.util.Date.

What you might want to do is use getTimestamp() instead.
getTimestamp() looks much better.

But why do you use internal classes of the database engine?

I don't use the internal classes in my application. I only set the value of a  java.sql.TIMESTAMP colum by PreparedStatement.setObject(int, Object). 
My Object is the ISO8601 String (e.g. "2012-11-08T12:40:11.156Z") and I have the problem that if I select the column again, the "outcoming" date is not the same as the "incoming" one. So I was looking for the error cause.

I wrote a JUnit test for you. There you can see that some strings will be correctly parsed (e.g. '2012-11-08T12:40:11.156Z') and some other ones like '2012-11-06T23:00:00.000Z' will not correctly parsed by the h2database.


It looks like there is a problem if the time in the ISO Strings is set to twelve o'clock at night.

Regards 
Steve

Thomas Mueller

unread,
Dec 15, 2012, 10:07:49 AM12/15/12
to H2 Google Group
Hi,

Thanks a lot for the test case! Yes, this is a bug. The problem is that in ValueTimestamp.parseTry, after converting to UTC, the time of the day was adjusted one hour (from 23:00:00 to 00:00:00), but the day was not adjusted (so it stayed, which was wrong).

I will try to fix this for the next release.

Regards,
Thomas



To view this discussion on the web visit https://groups.google.com/d/msg/h2-database/-/_57TU4mEgO4J.
Reply all
Reply to author
Forward
0 new messages