From b81a60a2605ae8c77e794b02830a4feadb3f57f6 Mon Sep 17 00:00:00 2001 From: Michael Payne Date: Sun, 26 Jan 2014 10:12:09 -0500 Subject: [PATCH] Parse date type as local time --- lib/types/textParsers.js | 3 ++- test/integration/client/type-coercion-tests.js | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/types/textParsers.js b/lib/types/textParsers.js index 1266423fc..4e909eb50 100644 --- a/lib/types/textParsers.js +++ b/lib/types/textParsers.js @@ -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); diff --git a/test/integration/client/type-coercion-tests.js b/test/integration/client/type-coercion-tests.js index 687e8fd0a..05dda987d 100644 --- a/test/integration/client/type-coercion-tests.js +++ b/test/integration/client/type-coercion-tests.js @@ -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)); });