From 2ef1bbf8dec6ef364a840bcb28fbb0a8540fe67d Mon Sep 17 00:00:00 2001 From: bmc Date: Mon, 22 Apr 2013 04:57:46 -0500 Subject: [PATCH] Parse minutes in timezone description Minutes in timezones are separated with a colon from the hour. This closes #309 --- lib/types/textParsers.js | 11 +++++++---- test/unit/client/typed-query-results-tests.js | 4 ++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/types/textParsers.js b/lib/types/textParsers.js index 00b70c5e..0a49ec6b 100644 --- a/lib/types/textParsers.js +++ b/lib/types/textParsers.js @@ -3,8 +3,7 @@ var arrayParser = require(__dirname + "/arrayParser.js"); //parses PostgreSQL server formatted date strings into javascript date objects var parseDate = function(isoDate) { //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{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})(\.\d{1,})?/; var match = dateMatcher.exec(isoDate); //could not parse date @@ -31,10 +30,13 @@ var parseDate = function(isoDate) { mili = 1000 * parseFloat(miliString); } - var tZone = /([Z|+\-])(\d{2})?(\d{2})?/.exec(isoDate.split(' ')[1]); + //match timezones like the following: + //Z (UTC) + //-05 + //+06:30 + var tZone = /([Z|+\-])(\d{2})?:?(\d{2})?/.exec(isoDate.split(' ')[1]); //minutes to adjust for timezone var tzAdjust = 0; - if(tZone) { var type = tZone[1]; switch(type) { @@ -53,6 +55,7 @@ var parseDate = function(isoDate) { var utcOffset = Date.UTC(year, month, day, hour, min, seconds, mili); return new Date(utcOffset - (tzAdjust * 60* 1000)); } + //no timezone information else { return new Date(year, month, day, hour, min, seconds, mili); } diff --git a/test/unit/client/typed-query-results-tests.js b/test/unit/client/typed-query-results-tests.js index 6ee768e5..ab48137b 100644 --- a/test/unit/client/typed-query-results-tests.js +++ b/test/unit/client/typed-query-results-tests.js @@ -78,11 +78,11 @@ test('typed results', function() { name: 'timestamptz with minutes in timezone', format: 'text', dataTypeID: 1184, - actual: '2010-10-31 14:54:13.74-0530', + actual: '2010-10-31 14:54:13.74-05:30', expected: function(val) { assert.UTCDate(val, 2010, 9, 31, 20, 24, 13, 740); } - },{ + }, { name: 'timestamptz with other milisecond digits dropped', format: 'text', dataTypeID: 1184,