brianc / node-pg-types

Type parsing for node-postgres
271 stars 56 forks source link

Inconsistent Date parsing #159

Closed t1a2l closed 2 months ago

t1a2l commented 2 months ago

Hello, I save data in my db as timestamp with timezone "2024-08-15 16:38:35+03", but when I extract the data using node and knex i get "2024-08-15T13:38:35.000Z". After some checking when I get an object from the database to the node server if I use:


pg.types.setTypeParser(pg.types.builtins.TIMESTAMPZ, (value) => {
  return parseDate (value);
});```

I see that the date is indeed converted to the 000Z format rather then stay in the +0X format.

But I also get an array as one of the properties of that object, and item in that array that has a timestamp do not go through the parser, any reason for that?
t1a2l commented 2 months ago

You can close- it seems that because row to josn, it is all a json and therefore not converted, also the function "row_to_json" does a convertion from "YYYY-MM-DD HH:mm:ss+03" to "YYYY-MM-DDTHH:mm:ss+03:00". so what needs to be done is:


pg.types.setTypeParser(pg.types.builtins.TIMESTAMPTZ, (value) => {
  let moment = require('moment');
  return moment(value).format();
});```

to make it consistent.