I would like to be able to create a datetime property that is two-way compatible with the java.util.Date type and a temporal date function (e.g. datetime() ) or other Cypher current date generator function.
Using a @NodeEntity object in java, a Date type property gets stored in Neo4j as a STRING with the format: 2019-03-26T18:55:01.132Z
Using the datetime() temporal function in Neo4j, the same date is stored as a STRING with the format: 2019-03-26T18:55:01.132000000Z
The only difference is the additional zeroes for micro- and nano-seconds. The stored java format can be converted to a datetime() and temporal operators applied, so that is not an issue.
The problem is that if the date field is created in Cypher using the datetime() function, it is returned to the java entity as a ZonedDateTime, and I get this exception:
java.lang.ClassCastException: java.time.ZonedDateTime cannot be cast to java.lang.String
at org.neo4j.ogm.typeconversion.DateStringConverter.toEntityAttribute(DateStringConverter.java:40)
Nodes created using a java entity convert back to Date just fine, it is only date properties updated via temporal instant functions that have this issue.
My question is...is there a temporal function that will store the proper datetime format for conversion? The closest I am able to come is this:
RETURN datetime.truncate('second', datetime())
"2019-03-26T19:52:48Z"
but that still throws the exception because of the missing seconds portion. Which leads me to believe this should solve my problem, alas it does not appear to truncate properly:
RETURN datetime.truncate('millisecond', datetime())
"2019-03-26T19:53:33.902000000Z"
Am I correct in assuming the returned value should be?:
"2019-03-26T19:53:33.902Z"
Is there a bug in the truncate function, or in my thinking? I would appreciate any insight.