Skip to content

[Feature Request]: Allow float values in Durations #768

@dmoree

Description

@dmoree

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 [email protected]: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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions