Skip to content

Temporal types #474

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

Merged
merged 20 commits into from
Mar 15, 2018
Merged

Temporal types #474

merged 20 commits into from
Mar 15, 2018

Conversation

lutovich
Copy link
Contributor

@lutovich lutovich commented Mar 7, 2018

PR makes driver support new temporal Cypher types:

  • Date exposed as java.time.LocalDate
  • Time exposed as java.time.OffsetTime
  • LocalTime exposed as java.time.LocalTime
  • LocalDateTime exposed as java.time.LocalDateTime
  • DateTime exposed as java.time.ZonedDateTime
  • Duration exposed as custom org.neo4j.driver.v1.types.Duration interface containing months, days, seconds and nanoseconds

Also simplified couple things around the Value class hierarchy.

lutovich added 18 commits March 7, 2018 14:14
Format with type was never used, all values have always been formatted
"by value". This commit just forces all `Value` implementations to
have `#toString()`.
Driver is now able to send and receive instances of Date type. They are
represented as `java.time.LocalDate` objects.
It is useless because current driver version is a pre-release version.
Driver is now able to send and receive instances of Time type. They are
represented as `java.time.OffsetTime` objects.
Driver is now able to send and receive instances of LocalTime type.
They are represented as `java.time.LocalTime` objects.
Driver is now able to send and receive instances of LocalDateTime type.
They are represented as `java.time.LocalDateTime` objects.
Driver is now able to send and receive instances of DateTime type.
They are represented as `java.time.ZonedDateTime` objects.
`ZonedDateTime` instances contain time zone information either as
numeric offset or as a zone id/name.
Driver is now able to send and receive instances of Duration type.
They are represented as instances of custom `org.neo4j.driver.v1.types.Duration`
interface. It's needed because Cypher's duration contains months, days,
seconds and nanoseconds. There exists no default class in `java.time`
package to represent a combination of these temporal values.
Removed "_TyCon" suffix, made code use `#toString()`
instead of `#typeName()`.
Instead of direct constructor invocation. So creation of value
implementations and internal classes only live in `Values` helper
class and is not duplicated.
By extracting generic test methods.
To assert that driver can send and receive DateTime with time zone
information as offset and zone name.
By using method references and lambdas instead of static final
function implementations.
if ( value instanceof LocalTime ) { return value( (LocalTime) value ); }
if ( value instanceof LocalDateTime ) { return value( (LocalDateTime) value ); }
if ( value instanceof ZonedDateTime ) { return value( (ZonedDateTime) value ); }
if ( value instanceof Duration ) { return value( (Duration) value ); }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems this Duration is our org.neo4j.driver.v1.types.Duration type, do we also want to support java native Duration and/or Period?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in a355fc4

private final long months;
private final long days;
private final long seconds;
private final long nanoseconds;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe instead of having months, days, seconds, nanoseconds 4 field, we could have Period period and Duration duration? Then the calculation such as add and minus would be easier?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We receive months and days as longs from the database but java.time.Period only allows ints

* Value that represents a duration can be created using {@link Values#duration(long, long, long, long)} method.
*/
@Immutable
public interface Duration extends TemporalAmount
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe IsoStandardDuration?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed to IsoDuration in bb31fc0

@lutovich lutovich force-pushed the 1.6-temporal-types branch 2 times, most recently from 4023f8a to a5f149e Compare March 13, 2018 22:55
So it does not clash with `java.time.Duration` and specifies that
it's a combination of date-based amount and time-based amount.
Driver represents duration as a custom `IsoDuration` interface. It's a
combination of date-based amount and time-based amount. This commit
makes driver accept `java.time.Period` and `java.time.Duration` as
parameters and convert them to `IsoDuration`.
Copy link
Contributor

@ali-ince ali-ince left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good to me.

@technige used WITH $x AS x RETURN x.hour, x.minute, x.second kind of queries in ITs which I think is a good way to check consistency across all layers. We may also consider it for the rest of the drivers.

@ali-ince ali-ince merged commit 093c607 into neo4j:1.6 Mar 15, 2018
@lutovich lutovich deleted the 1.6-temporal-types branch March 19, 2018 09:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants