-
Notifications
You must be signed in to change notification settings - Fork 155
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
Temporal types #474
Conversation
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 ); } |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 long
s from the database but java.time.Period
only allows int
s
* Value that represents a duration can be created using {@link Values#duration(long, long, long, long)} method. | ||
*/ | ||
@Immutable | ||
public interface Duration extends TemporalAmount |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe IsoStandardDuration
?
There was a problem hiding this comment.
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
4023f8a
to
a5f149e
Compare
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`.
a5f149e
to
a355fc4
Compare
There was a problem hiding this 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.
PR makes driver support new temporal Cypher types:
java.time.LocalDate
java.time.OffsetTime
java.time.LocalTime
java.time.LocalDateTime
java.time.ZonedDateTime
org.neo4j.driver.v1.types.Duration
interface containing months, days, seconds and nanosecondsAlso simplified couple things around the
Value
class hierarchy.