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

Returning the postgres DATE type #181

Open
StefanHoutzager opened this issue Oct 7, 2020 · 0 comments
Open

Returning the postgres DATE type #181

StefanHoutzager opened this issue Oct 7, 2020 · 0 comments
Labels
bug Something isn't working

Comments

@StefanHoutzager
Copy link

StefanHoutzager commented Oct 7, 2020

Currently I get my dates (defined with datatype DATE) back as f.e. "2021-03-02T23:00:00.000Z" while pgadmin gives 2021-03-03. So I get the wrong date back (and a timestamp was added).
You can find the same issue in node-postgres brianc/node-postgres#818 where someone suggests a workaround in the end (that I just tested, it works). brianc/node-postgres#818 , see a paste of the snippet below. Can this be fixed in deno-postgres? My proposal would be to change decodeDate in decode.ts to simply

function decodeDate(dateStr: string): Date {
    return new Date(dateStr + 'T00:00:00Z');
}

of course that works for year 0001 too. ;-) For null values in the postgress date the function decodeDate is not executed.

/* Node postgres date fix /
var Moment = require('moment');
var parseDate = function parseDate(val) {
return val === null ? null : Moment(val).format('YYYY-MM-DD')
};
var types = pg.types;
var DATATYPE_DATE = 1082;
types.setTypeParser(DATATYPE_DATE, function(val) {
return val === null ? null : parseDate(val)
});
/ Node postgres date fix - end */
StefanHoutzager added a commit to StefanHoutzager/deno-postgres that referenced this issue Oct 7, 2020
…ateStr + 'T00:00:00Z')

/* text of issue denodrivers#181 copied */
Currently I get my dates (defined with datatype DATE) back as f.e. "2021-03-02T23:00:00.000Z" while pgadmin gives 2021-03-03. So I get the wrong date back (and a timestamp was added).
You can find the same issue in node-postgres brianc/node-postgres#818 where someone suggests a workaround in the end (that I just tested, it works). brianc/node-postgres#818 , see a paste of the snippet below. Can this be fixed in deno-postgres? My proposal would be to change decodeDate in decode.ts to simply

function decodeDate(dateStr: string): Date {
    return new Date(dateStr + 'T00:00:00Z');
}
of course that works for year 0001 too. ;-) For null values in the postgress date the function decodeDate is not executed.

/* Node postgres date fix /
var Moment = require('moment');
var parseDate = function parseDate(val) {
return val === null ? null : Moment(val).format('YYYY-MM-DD')
};
var types = pg.types;
var DATATYPE_DATE = 1082;
types.setTypeParser(DATATYPE_DATE, function(val) {
return val === null ? null : parseDate(val)
});
/ Node postgres date fix - end */
@bombillazo bombillazo added the bug Something isn't working label Feb 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants