Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposed solution to issue #50 #53

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 22 additions & 5 deletions lib/textParsers.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var array = require('postgres-array')
var ap = require('ap')
var arrayParser = require('./arrayParser');
var parseDate = require('postgres-date');
var parseTimestamp = require('postgres-date');
var parseInterval = require('postgres-interval');
var parseByteA = require('postgres-bytea');

Expand Down Expand Up @@ -66,6 +66,19 @@ var parseDateArray = function(value) {
return p.parse();
};

var parseTimestampArray = function(value) {
if (!value) { return null; }

var p = arrayParser.create(value, function(entry) {
if (entry !== null) {
entry = parseTimestamp(entry);
}
return entry;
});

return p.parse();
};

var parseByteAArray = function(value) {
var arr = parseStringArray(value);
if (!arr) return arr;
Expand Down Expand Up @@ -136,6 +149,10 @@ var parseCircle = function(value) {
return result;
};

var parseDate = function(value) {
return value;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this function.

var init = function(register) {
register(20, parseBigInteger); // int8
register(21, parseInteger); // int2
Expand All @@ -145,8 +162,8 @@ var init = function(register) {
register(701, parseFloat); // float8/double
register(16, parseBool);
register(1082, parseDate); // date
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove 1082

register(1114, parseDate); // timestamp without timezone
register(1184, parseDate); // timestamp
register(1114, parseTimestamp); // timestamp without timezone
register(1184, parseTimestamp); // timestamp
register(600, parsePoint); // point
register(718, parseCircle); // circle
register(1000, parseBoolArray);
Expand All @@ -162,9 +179,9 @@ var init = function(register) {
register(1015, parseStringArray); //varchar
register(1008, parseStringArray);
register(1009, parseStringArray);
register(1115, parseDateArray); // timestamp without time zone[]
register(1115, parseTimestampArray); // timestamp without time zone[]
register(1182, parseDateArray); // _date
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change to parseStringArray

register(1185, parseDateArray); // timestamp with time zone[]
register(1185, parseTimestampArray); // timestamp with time zone[]
register(1186, parseInterval);
register(17, parseByteA);
register(114, JSON.parse.bind(JSON)); // json
Expand Down
26 changes: 5 additions & 21 deletions test/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ exports.timestamp = {
id: 1114,
tests: [
[
'2010-10-31 00:00:00',
'2010-10-31 00:00:00',
function (t, value) {
t.equal(
value.toUTCString(),
Expand All @@ -122,15 +122,7 @@ exports.date = {
format: 'text',
id: 1082,
tests: [
['2010-10-31', function (t, value) {
var now = new Date(2010, 9, 31)
dateEquals(
2010,
now.getUTCMonth(),
now.getUTCDate(),
now.getUTCHours(), 0, 0, 0)(t, value)
t.equal(value.getHours(), now.getHours())
}]
['2010-10-31', '2010-10-31']
]
}

Expand Down Expand Up @@ -297,17 +289,9 @@ exports['array/date'] = {
id: 1182,
tests: [
['{2014-01-01,2015-12-31}', function (t, value) {
var expecteds = [new Date(2014, 0, 1), new Date(2015, 11, 31)]
t.equal(value.length, 2)
value.forEach(function (date, index) {
var expected = expecteds[index]
dateEquals(
expected.getUTCFullYear(),
expected.getUTCMonth(),
expected.getUTCDate(),
expected.getUTCHours(), 0, 0, 0)(t, date)
})
}]
t.deepEqual(value, ['2014-01-01', '2015-12-31'])
}
]
]
}

Expand Down