commit 60810ea0a06f5c82ef279749d74f8bda2efeb7db
parent a207e388db28c5c51091283403eafe946887de36
Author: Dan Stillman <dstillman@zotero.org>
Date: Thu, 11 May 2017 00:44:37 -0400
Fix access date without time coming from sync
Diffstat:
2 files changed, 28 insertions(+), 9 deletions(-)
diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js
@@ -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':
diff --git a/test/tests/itemTest.js b/test/tests/itemTest.js
@@ -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",