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

Change instanceof(Date) to util.types.isDate(Date) #2862

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Srayman
Copy link

@Srayman Srayman commented Nov 17, 2022

Fixes #2860. isDate handles additional cases where a Date object may not be an instance of Date. This impacts whether a date is correctly formatted with the correct timezone for the database.

@brianc
Copy link
Owner

brianc commented Nov 21, 2022

Thanks Srayman - is there a way you could include a unit/integration test for this? I often make tests for particular github issues here: https://github.com/brianc/node-postgres/tree/master/packages/pg/test/integration/gh-issues

@Srayman
Copy link
Author

Srayman commented Nov 22, 2022

I'll have to think about how to setup the Date object to properly test it. We're using a custom Rust library currently in our project and where this problem originated from. I'm looking to see if there's an easy way to recreate the issue natively in JS/TS. If you have any thoughts I'm open to suggestions on how to create a Date that is not an instance of Date.

@charmander
Copy link
Collaborator

vm.runInNewContext('new Date()')

should do it, IIRC

@Srayman
Copy link
Author

Srayman commented Nov 24, 2022

vm.runInNewContext('new Date()')

should do it, IIRC

Awesome, did not know about vm! That seems to do the trick locally for the 2862 test. Pushed the test and also updated the util function to use both methods to check for a date in case there are any edge cases the other direction. Let me know what you think.

@Srayman
Copy link
Author

Srayman commented Dec 8, 2022

Any feedback on this @brianc ?

packages/pg/lib/utils.js Outdated Show resolved Hide resolved
Copy link
Collaborator

@charmander charmander left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The package change looks good to me!

The test could be improved, but so could a lot of other tests. I think it’s fair to take care of it along with those :)

@charmander
Copy link
Collaborator

charmander commented Dec 16, 2022

Oh, I forgot pg still declares support for Node 8 (#2865). I don’t think util.types is compatible, unless it was backported without updating the docs. It’s not in CI…

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

Successfully merging this pull request may close these issues.

instanceof Date doesn't always catch all Date objects
3 participants