diff --git a/chrome/content/zotero/xpcom/date.js b/chrome/content/zotero/xpcom/date.js index a426f50590..74cc4c8e7c 100644 --- a/chrome/content/zotero/xpcom/date.js +++ b/chrome/content/zotero/xpcom/date.js @@ -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) { diff --git a/test/tests/dateTest.js b/test/tests/dateTest.js index 7ed218561f..be6d1a0012 100644 --- a/test/tests/dateTest.js +++ b/test/tests/dateTest.js @@ -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 () {