Skip to content

Commit

Permalink
Parse date type as local time
Browse files Browse the repository at this point in the history
  • Loading branch information
benighted committed Jan 26, 2014
1 parent 51a28c2 commit b81a60a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/types/textParsers.js
Expand Up @@ -14,7 +14,8 @@ var parseDate = function(isoDate) {
return null;
} else {
//it is a date in YYYY-MM-DD format
return new Date(isoDate);
//add time portion to force js to parse as local time
return new Date(isoDate + ' 00:00:00');
}
}
var isBC = /BC$/.test(isoDate);
Expand Down
5 changes: 3 additions & 2 deletions test/integration/client/type-coercion-tests.js
Expand Up @@ -202,13 +202,14 @@ helper.pg.connect(helper.config, assert.calls(function(err, client, done) {
if(!helper.config.binary) {
test("postgres date type", function() {
var client = helper.client();
var testDate = new Date (2010, 9, 31);
client.on('error', function(err) {
console.log(err);
client.end();
});
client.query("SELECT '2010-10-31'::date", assert.calls(function(err, result){
client.query("SELECT $1::date", [testDate], assert.calls(function(err, result){
assert.isNull(err);
assert.UTCDate(result.rows[0].date, 2010, 9, 31, 0, 0, 0, 0);
assert.strictEqual(result.rows[0].date.toString(), testDate.toString());
}));
client.on('drain', client.end.bind(client));
});
Expand Down

0 comments on commit b81a60a

Please sign in to comment.