mirror of
https://github.com/brianc/node-postgres.git
synced 2025-12-08 20:16:25 +00:00
Parse minutes in timezone description
Minutes in timezones are separated with a colon from the hour. This closes #309
This commit is contained in:
parent
bff8bc259c
commit
2ef1bbf8de
@ -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);
|
||||
}
|
||||
|
||||
@ -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,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user