neo4j / neo4j/neo4j-javascript-driver

`[Feature Request]`: Allow float values in Durations

Open
#768 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature request
Dominant language
JavaScript
Stars
917
Forks
158
Avg merge
2d 15h
Merged PRs (30d)
7

Description

Description

When inserting a node with a duration property into the database, float values are truncating leaving only integer values. Both the ISO 8601 standard and Neo4j allow for decimal fractions on values so long as the decimal fraction is on the smallest unit. For example P6.5M is valid, but P6.5M4D is not.

When creating a new Duration with 6.5 months however it is stored in the database as P6M since it calls int(months) in packDuration

The driver should allow for float values on month and day if resulting in valid duration. This ideally would have an assertValidDuration that would make sure float values are not passed improperly. Float values should only be accepted on:

  • months if days seconds and nanoseconds are zero.
  • days if seconds and nanoseconds are zero.

Asserting this would make sure the resulting duration would be valid.

Steps to reproduce
  1. Start local Neo4j instance
  2. Clone repository
git clone git@github.com:dmoree/neo4j-javascript-driver-issue-duration.git
  1. Run (creates duration and uses it when adding node in database)
npm start
  1. Check output and confirm in database that duration is incorrect.
Expected behavior

The duration should be stored as P6.5M0DT0S

Actual behavior

The duration is stored as P6M0DT0S

System

Neo4j Version: 4.3.3 Enterprise
Neo4j Mode: Single instance
Driver Version: 4.3.3 (javascript)
Operating System: macOS 11.5
Node Version: 14.16.0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in bolt-connection/src/packstream/packstream-v2.js at packDuration, linked from the report, and inspect how Duration values are validated and packed. Reproduce the case with the supplied repository and npm start, then verify that valid fractional months or days are preserved while invalid combinations are rejected and the database output matches the expected duration.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, neo4j
Domain
databases
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.