Merge pull request #480 from benighted/master
Fix for Y10k problem, see issue #441.
This commit is contained in:
commit
d246786461
@ -3,12 +3,12 @@ var arrayParser = require(__dirname + "/arrayParser.js");
|
|||||||
//parses PostgreSQL server formatted date strings into javascript date objects
|
//parses PostgreSQL server formatted date strings into javascript date objects
|
||||||
var parseDate = function(isoDate) {
|
var parseDate = function(isoDate) {
|
||||||
//TODO this could do w/ a refactor
|
//TODO this could do w/ a refactor
|
||||||
var dateMatcher = /(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})(\.\d{1,})?/;
|
var dateMatcher = /(\d{1,})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})(\.\d{1,})?/;
|
||||||
|
|
||||||
var match = dateMatcher.exec(isoDate);
|
var match = dateMatcher.exec(isoDate);
|
||||||
//could not parse date
|
//could not parse date
|
||||||
if(!match) {
|
if(!match) {
|
||||||
dateMatcher = /^(\d{4})-(\d{2})-(\d{2})$/;
|
dateMatcher = /^(\d{1,})-(\d{2})-(\d{2})$/;
|
||||||
match = dateMatcher.test(isoDate);
|
match = dateMatcher.test(isoDate);
|
||||||
if(!match) {
|
if(!match) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -151,19 +151,23 @@ test("timestampz round trip", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if(!helper.config.binary) {
|
if(!helper.config.binary) {
|
||||||
test('early AD & BC date', function() {
|
test('date range extremes', function() {
|
||||||
var client = helper.client();
|
var client = helper.client();
|
||||||
client.on('error', function(err) {
|
client.on('error', function(err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
client.end();
|
client.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
client.query('SELECT $1::TIMESTAMPTZ as when', ["0062-03-08 14:32:00"], assert.success(function(res) {
|
// PostgreSQL supports date range of 4713 BCE to 294276 CE
|
||||||
assert.equal(res.rows[0].when.getFullYear(), 62);
|
// http://www.postgresql.org/docs/9.2/static/datatype-datetime.html
|
||||||
|
// ECMAScript supports date range of Apr 20 271821 BCE to Sep 13 275760 CE
|
||||||
|
// http://ecma-international.org/ecma-262/5.1/#sec-15.9.1.1
|
||||||
|
client.query('SELECT $1::TIMESTAMPTZ as when', ["275760-09-13 00:00:00 GMT"], assert.success(function(res) {
|
||||||
|
assert.equal(res.rows[0].when.getFullYear(), 275760);
|
||||||
}))
|
}))
|
||||||
|
|
||||||
client.query('SELECT $1::TIMESTAMPTZ as when', ["0062-03-08 14:32:00 BC"], assert.success(function(res) {
|
client.query('SELECT $1::TIMESTAMPTZ as when', ["4713-12-31 12:31:59 BC GMT"], assert.success(function(res) {
|
||||||
assert.equal(res.rows[0].when.getFullYear(), -62);
|
assert.equal(res.rows[0].when.getFullYear(), -4713);
|
||||||
}))
|
}))
|
||||||
|
|
||||||
client.on('drain', client.end.bind(client));
|
client.on('drain', client.end.bind(client));
|
||||||
|
Loading…
Reference in New Issue
Block a user