Skip to content

Commit b7f8429

Browse files
William Beckerbrianc
William Becker
authored andcommitted
handle early dates (< 100AD)
1 parent 5c23389 commit b7f8429

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

lib/types/textParsers.js

+14-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ var parseDate = function(isoDate) {
1717
return new Date(isoDate);
1818
}
1919
}
20-
var year = match[1];
20+
var isBC = /BC$/.test(isoDate);
21+
var _year = parseInt(match[1], 10);
22+
var isFirstCentury = (_year > 0) && (_year < 100);
23+
var year = (isBC ? "-" : "") + match[1];
24+
2125
var month = parseInt(match[2],10)-1;
2226
var day = match[3];
2327
var hour = parseInt(match[4],10);
@@ -37,6 +41,7 @@ var parseDate = function(isoDate) {
3741
var tZone = /([Z|+\-])(\d{2})?:?(\d{2})?/.exec(isoDate.split(' ')[1]);
3842
//minutes to adjust for timezone
3943
var tzAdjust = 0;
44+
var date;
4045
if(tZone) {
4146
var type = tZone[1];
4247
switch(type) {
@@ -53,13 +58,18 @@ var parseDate = function(isoDate) {
5358
}
5459

5560
var utcOffset = Date.UTC(year, month, day, hour, min, seconds, mili);
56-
return new Date(utcOffset - (tzAdjust * 60* 1000));
61+
62+
date = new Date(utcOffset - (tzAdjust * 60* 1000));
5763
}
5864
//no timezone information
5965
else {
60-
return new Date(year, month, day, hour, min, seconds, mili);
66+
date = new Date(year, month, day, hour, min, seconds, mili);
6167
}
62-
68+
69+
if (isFirstCentury) {
70+
date.setUTCFullYear(year);
71+
}
72+
return date;
6373
};
6474

6575
var parseBool = function(val) {

0 commit comments

Comments
 (0)