Skip to content

Disable automatic parsing of DateTime values #575

Closed as not planned
Closed as not planned
@CharlBest

Description

@CharlBest

Neo4j Version: 4.0 Enterprise Docker
Neo4j Mode: Single instance
Driver version: JS driver ^4.0.2
Operating System: Windows 10

Steps to reproduce

  1. Start Neo4j
  2. Run a query with the driver (return datetime())

Expected behavior

I expect the datetime() that is being returned to be in a string format.

Actual behavior

It parses the value into a custom object with properties like day, month, year, etc.
I can see how this can be useful but the string value is just as valuable. If I want to send the date property to the frontend app I would always have to convert it otherwise the toString function will be lost on the object.

It would be nice to have an option on a per query basis or even better a global options setting to disable parsing the datetime and just return the string value.

This is my horrible temporary workaround.

if (result.records) {
    for (const record of result.records) {
        for (const recordKey of record.keys) {
            const object = record.get(recordKey);
            if (!Array.isArray(object)) {
                for (const key in object) {
                    if (object.hasOwnProperty(key) && isDateTime(object[key])) {
                        object[key] = object[key].toString();
                    }
                }
            }
        }
    }
}

PS: this does not take into account nested objects or arrays.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions