Skip to content

Commit 2ef1bbf

Browse files
committed
Parse minutes in timezone description
Minutes in timezones are separated with a colon from the hour. This closes brianc#309
1 parent bff8bc2 commit 2ef1bbf

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

lib/types/textParsers.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ 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 =
7-
/(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})(\.\d{1,})?/;
6+
var dateMatcher = /(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})(\.\d{1,})?/;
87

98
var match = dateMatcher.exec(isoDate);
109
//could not parse date
@@ -31,10 +30,13 @@ var parseDate = function(isoDate) {
3130
mili = 1000 * parseFloat(miliString);
3231
}
3332

34-
var tZone = /([Z|+\-])(\d{2})?(\d{2})?/.exec(isoDate.split(' ')[1]);
33+
//match timezones like the following:
34+
//Z (UTC)
35+
//-05
36+
//+06:30
37+
var tZone = /([Z|+\-])(\d{2})?:?(\d{2})?/.exec(isoDate.split(' ')[1]);
3538
//minutes to adjust for timezone
3639
var tzAdjust = 0;
37-
3840
if(tZone) {
3941
var type = tZone[1];
4042
switch(type) {
@@ -53,6 +55,7 @@ var parseDate = function(isoDate) {
5355
var utcOffset = Date.UTC(year, month, day, hour, min, seconds, mili);
5456
return new Date(utcOffset - (tzAdjust * 60* 1000));
5557
}
58+
//no timezone information
5659
else {
5760
return new Date(year, month, day, hour, min, seconds, mili);
5861
}

test/unit/client/typed-query-results-tests.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ test('typed results', function() {
7878
name: 'timestamptz with minutes in timezone',
7979
format: 'text',
8080
dataTypeID: 1184,
81-
actual: '2010-10-31 14:54:13.74-0530',
81+
actual: '2010-10-31 14:54:13.74-05:30',
8282
expected: function(val) {
8383
assert.UTCDate(val, 2010, 9, 31, 20, 24, 13, 740);
8484
}
85-
},{
85+
}, {
8686
name: 'timestamptz with other milisecond digits dropped',
8787
format: 'text',
8888
dataTypeID: 1184,

0 commit comments

Comments
 (0)