strToDate(): Don't parse 01/01/08 as the year 8

Regression from b7dc0d8b0a (5.0.81)
This commit is contained in:
Dan Stillman 2020-05-28 06:18:21 -04:00
parent c882488ef7
commit 0620b16d3e
2 changed files with 20 additions and 7 deletions

View file

@ -317,7 +317,9 @@ Zotero.Date = new function(){
}
}
var zeroYear = date.year && date.year.toString().startsWith('0');
// Parse pre-1000 years with leading zeroes (001, 0001, 012, 0012, 0123, but not 08)
var zeroYear = date.year
&& /^(0{2,3}[1-9]|0{1,2}[1-9][0-9]|0[1-9][0-9]{2})$/.test(date.year.toString());
if(date.year) date.year = parseInt(date.year, 10);
if(date.day) date.day = parseInt(date.day, 10);
if(date.month) {

View file

@ -183,14 +183,25 @@ describe("Zotero.Date", function() {
});
it("should parse two- and three-digit dates with leading zeros", function () {
var o = Zotero.Date.strToDate('0068');
assert.equal(o.year, 68);
var o;
o = Zotero.Date.strToDate('068');
assert.equal(o.year, 68);
o = Zotero.Date.strToDate('001');
assert.equal(o.year, 1);
o = Zotero.Date.strToDate('0168');
assert.equal(o.year, 168);
o = Zotero.Date.strToDate('0001');
assert.equal(o.year, 1);
o = Zotero.Date.strToDate('012');
assert.equal(o.year, 12);
o = Zotero.Date.strToDate('0012');
assert.equal(o.year, 12);
o = Zotero.Date.strToDate('0123');
assert.equal(o.year, 123);
o = Zotero.Date.strToDate('01/01/08');
assert.equal(o.year, 2008);
});
it("should parse two-digit year greater than current year as previous century", function () {