Skip to content

Commit 2716f95

Browse files
committed
Merge pull request #514 from benighted/parse-date-as-local
Parse date type as local time
2 parents ff8fb61 + b81a60a commit 2716f95

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

lib/types/textParsers.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ var parseDate = function(isoDate) {
1414
return null;
1515
} else {
1616
//it is a date in YYYY-MM-DD format
17-
return new Date(isoDate);
17+
//add time portion to force js to parse as local time
18+
return new Date(isoDate + ' 00:00:00');
1819
}
1920
}
2021
var isBC = /BC$/.test(isoDate);

test/integration/client/type-coercion-tests.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -202,13 +202,14 @@ helper.pg.connect(helper.config, assert.calls(function(err, client, done) {
202202
if(!helper.config.binary) {
203203
test("postgres date type", function() {
204204
var client = helper.client();
205+
var testDate = new Date (2010, 9, 31);
205206
client.on('error', function(err) {
206207
console.log(err);
207208
client.end();
208209
});
209-
client.query("SELECT '2010-10-31'::date", assert.calls(function(err, result){
210+
client.query("SELECT $1::date", [testDate], assert.calls(function(err, result){
210211
assert.isNull(err);
211-
assert.UTCDate(result.rows[0].date, 2010, 9, 31, 0, 0, 0, 0);
212+
assert.strictEqual(result.rows[0].date.toString(), testDate.toString());
212213
}));
213214
client.on('drain', client.end.bind(client));
214215
});

0 commit comments

Comments
 (0)