Skip to content

Commit d246786

Browse files
committed
Merge pull request #480 from benighted/master
Fix for Y10k problem, see issue #441.
2 parents bbea5d6 + e6a2525 commit d246786

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

lib/types/textParsers.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ var arrayParser = require(__dirname + "/arrayParser.js");
33
//parses PostgreSQL server formatted date strings into javascript date objects
44
var parseDate = function(isoDate) {
55
//TODO this could do w/ a refactor
6-
var dateMatcher = /(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})(\.\d{1,})?/;
6+
var dateMatcher = /(\d{1,})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})(\.\d{1,})?/;
77

88
var match = dateMatcher.exec(isoDate);
99
//could not parse date
1010
if(!match) {
11-
dateMatcher = /^(\d{4})-(\d{2})-(\d{2})$/;
11+
dateMatcher = /^(\d{1,})-(\d{2})-(\d{2})$/;
1212
match = dateMatcher.test(isoDate);
1313
if(!match) {
1414
return null;

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

+9-5
Original file line numberDiff line numberDiff line change
@@ -151,19 +151,23 @@ test("timestampz round trip", function() {
151151
});
152152

153153
if(!helper.config.binary) {
154-
test('early AD & BC date', function() {
154+
test('date range extremes', function() {
155155
var client = helper.client();
156156
client.on('error', function(err) {
157157
console.log(err);
158158
client.end();
159159
});
160160

161-
client.query('SELECT $1::TIMESTAMPTZ as when', ["0062-03-08 14:32:00"], assert.success(function(res) {
162-
assert.equal(res.rows[0].when.getFullYear(), 62);
161+
// PostgreSQL supports date range of 4713 BCE to 294276 CE
162+
// http://www.postgresql.org/docs/9.2/static/datatype-datetime.html
163+
// ECMAScript supports date range of Apr 20 271821 BCE to Sep 13 275760 CE
164+
// http://ecma-international.org/ecma-262/5.1/#sec-15.9.1.1
165+
client.query('SELECT $1::TIMESTAMPTZ as when', ["275760-09-13 00:00:00 GMT"], assert.success(function(res) {
166+
assert.equal(res.rows[0].when.getFullYear(), 275760);
163167
}))
164168

165-
client.query('SELECT $1::TIMESTAMPTZ as when', ["0062-03-08 14:32:00 BC"], assert.success(function(res) {
166-
assert.equal(res.rows[0].when.getFullYear(), -62);
169+
client.query('SELECT $1::TIMESTAMPTZ as when', ["4713-12-31 12:31:59 BC GMT"], assert.success(function(res) {
170+
assert.equal(res.rows[0].when.getFullYear(), -4713);
167171
}))
168172

169173
client.on('drain', client.end.bind(client));

0 commit comments

Comments
 (0)