Skip to content

Commit

Permalink
Fix access date without time coming from sync
Browse files Browse the repository at this point in the history
  • Loading branch information
dstillman committed May 11, 2017
1 parent a207e38 commit 60810ea
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
23 changes: 14 additions & 9 deletions chrome/content/zotero/xpcom/data/item.js
Expand Up @@ -4099,24 +4099,29 @@ Zotero.Item.prototype.fromJSON = function (json) {
break;

case 'accessDate':
if (val && !Zotero.Date.isSQLDate(val)) {
let d = Zotero.Date.isoToDate(val);
if (!d) {
Zotero.logError(`Discarding invalid ${field} '${val}' for item ${this.libraryKey}`);
continue;
}
val = Zotero.Date.dateToSQL(d, true);
}
this.setField(field, val);
setFields[field] = true;
break;

case 'dateAdded':
case 'dateModified':
if (val) {
let d = Zotero.Date.isoToDate(val);
if (!d) {
Zotero.logError("Discarding invalid " + field + " '" + val
+ "' for item " + this.libraryKey);
Zotero.logError(`Discarding invalid ${field} '${val}' for item ${this.libraryKey}`);
continue;
}
val = Zotero.Date.dateToSQL(d, true);
}
if (field == 'accessDate') {
this.setField(field, val);
setFields[field] = true;
}
else {
this[field] = val;
}
this[field] = val;
break;

case 'parentItem':
Expand Down
14 changes: 14 additions & 0 deletions test/tests/itemTest.js
Expand Up @@ -1433,6 +1433,20 @@ describe("Zotero.Item", function () {
assert.equal(item.dateModified, '2015-06-07 20:58:00');
})

it("should accept ISO 8601 access date without time", function* () {
var json = {
itemType: "journalArticle",
accessDate: "2015-06-07",
dateAdded: "2015-06-07T20:57:00Z",
dateModified: "2015-06-07T20:58:00Z",
};
var item = new Zotero.Item;
item.fromJSON(json);
assert.equal(item.getField('accessDate'), '2015-06-07');
assert.equal(item.dateAdded, '2015-06-07 20:57:00');
assert.equal(item.dateModified, '2015-06-07 20:58:00');
})

it("should ignore non–ISO 8601 dates", function* () {
var json = {
itemType: "journalArticle",
Expand Down

0 comments on commit 60810ea

Please sign in to comment.