mirror of
https://github.com/brianc/node-postgres.git
synced 2025-12-08 20:16:25 +00:00
handle early dates (< 100AD)
This commit is contained in:
parent
5c233896f1
commit
b7f8429ff7
@ -17,7 +17,11 @@ var parseDate = function(isoDate) {
|
||||
return new Date(isoDate);
|
||||
}
|
||||
}
|
||||
var year = match[1];
|
||||
var isBC = /BC$/.test(isoDate);
|
||||
var _year = parseInt(match[1], 10);
|
||||
var isFirstCentury = (_year > 0) && (_year < 100);
|
||||
var year = (isBC ? "-" : "") + match[1];
|
||||
|
||||
var month = parseInt(match[2],10)-1;
|
||||
var day = match[3];
|
||||
var hour = parseInt(match[4],10);
|
||||
@ -37,6 +41,7 @@ var parseDate = function(isoDate) {
|
||||
var tZone = /([Z|+\-])(\d{2})?:?(\d{2})?/.exec(isoDate.split(' ')[1]);
|
||||
//minutes to adjust for timezone
|
||||
var tzAdjust = 0;
|
||||
var date;
|
||||
if(tZone) {
|
||||
var type = tZone[1];
|
||||
switch(type) {
|
||||
@ -53,13 +58,18 @@ var parseDate = function(isoDate) {
|
||||
}
|
||||
|
||||
var utcOffset = Date.UTC(year, month, day, hour, min, seconds, mili);
|
||||
return new Date(utcOffset - (tzAdjust * 60* 1000));
|
||||
|
||||
date = new Date(utcOffset - (tzAdjust * 60* 1000));
|
||||
}
|
||||
//no timezone information
|
||||
else {
|
||||
return new Date(year, month, day, hour, min, seconds, mili);
|
||||
date = new Date(year, month, day, hour, min, seconds, mili);
|
||||
}
|
||||
|
||||
|
||||
if (isFirstCentury) {
|
||||
date.setUTCFullYear(year);
|
||||
}
|
||||
return date;
|
||||
};
|
||||
|
||||
var parseBool = function(val) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user