denodrivers / denodrivers/postgres
Returning the postgres DATE type
- Dominant language
- TypeScript
- Stars
- 655
- Forks
- 97
- PR merge metrics
- No merged PRs in 30d
Description
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 https://github.com/brianc/node-postgres/issues/818 where someone suggests a workaround in the end (that I just tested, it works). https://github.com/brianc/node-postgres/issues/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 */
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.