Skip to content
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

Disable automatic parsing of DateTime values #575

Open
CharlBest opened this issue Jun 2, 2020 · 3 comments · May be fixed by #1002
Open

Disable automatic parsing of DateTime values #575

CharlBest opened this issue Jun 2, 2020 · 3 comments · May be fixed by #1002

Comments

@CharlBest
Copy link

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.

@Overdrivr
Copy link

I'm facing a similar issue, is it due to the fact that neo4j-driver serializes as a JSON object (with fields year, month, day, etc.) instead of an ISO date string ?

Most libs that deal with dates try to stick to native JS Dates, is there a motivation for not doing this here ?

@bigmontz
Copy link
Contributor

Neo4j has a well define type system, so different temporal types has their own representation inside the database. These types are also mapped in specialised structures in the client/server communication and in the code itself. This is the reason we have all this temporal types in the javascript driver.

We could provide toJSON method to these classes, this could avoid the extra-steps when you just want to serialize the record to json.

@bigmontz bigmontz linked a pull request Sep 20, 2022 that will close this issue
@bigmontz bigmontz self-assigned this Sep 20, 2022
@bigmontz
Copy link
Contributor

We actually could not provide the .toJSON method since it will be a breaking change since it is possible to have code depending on the current behaviour.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants