-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Date-fields are returned as ISO8061 date-time strings #1844
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
Comments
It’s a |
Even if it's a Date object, it does not know if it is date or date-time, which the date-field in the db is supposed to preserve. The expected return value would be a date without time. Since the Date-object includes time, you shouldn't turn it into a date object. |
I just ran into the same issue. The whole point of postgres If the notion of time was needed then the |
For what it worth, the parsed I think, by default, the library should return both the |
Time wasted around this. |
The problem is not if the return value is a If But if I ran In fact, I fixed all my issues with:
So I now raise the question, what is |
I don't see First line of code
But such offset makes no sense at all. It's just a date stored in a database, with no time and as such, timezone offset not applicable at all. And even if time was in there, the machine that wrote to the database is in UTC. The machine where I am connecting to the database from is not, which I guess is the source of such evil.... |
Just for clarification, defaults are not to use UTC: Line 56 in 06fbe19
|
I guess it isn’t if you want to distinguish the return value from the process of parsing, but that’s not what people have been talking about. The only sensible string return value is the form |
Going through the docs it states that I can not apply such method to But I understand what you are saying @charmander. |
see discussion here brianc/node-pg-types#50 |
For anyone interested, this behaviour is planned to be changed in next version of pg-types (4.x), PR is merged here brianc/node-pg-types#121. |
Solution - to override parser for
|
Can you tell me what this is effectively doing? Is this returning the value parsed as a |
@robross0606 It returns a |
It wasn't immediately obvious to me that array types are handled using a separate OID. The typname value for array types are the regular type name with var types = require('pg').types
types.setTypeParser(1182, v => {
v = v.substring(1, v.length - 1)
return v.split(',')
}) This worked for me. Do let me know if there's a better way to handle the array using the internal array parser from pg-types. |
pg.types.setTypeParser(1182, v => v.substring(1, v.length - 1).split(',')); //1182 for date[] |
3 years later and the behavior is still to force "date" fields to a JS Date. Did this get reverted? Did it not happen? This is not sane behavior. |
@markedwards A new major version of pg-types has been released with the fix, but there hasn’t been a corresponding new major version of pg to depend on the new pg-types. |
Situation
I have a date field, stored on the format YYYY-MM-DD (i.e. 2019-02-27).
Expectations
I expect it to be returned on the same format as the YYYY-MM-DD. (2019-02-27).
Results
I end up retrieving the value as an ISO8061 date-time string. YYYY-MM-DDThh:mm:ss... Z. (2019-02-26T23:00:00.000Z).
Workaround:
Simply return the value from the database, rather than converting to a Date-object.
pg version 7.7.1
knex/knex#3071
The text was updated successfully, but these errors were encountered: