Fix access date without time coming from sync
This commit is contained in:
parent
a207e388db
commit
60810ea0a0
2 changed files with 28 additions and 9 deletions
|
@ -4099,24 +4099,29 @@ Zotero.Item.prototype.fromJSON = function (json) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'accessDate':
|
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 'dateAdded':
|
||||||
case 'dateModified':
|
case 'dateModified':
|
||||||
if (val) {
|
if (val) {
|
||||||
let d = Zotero.Date.isoToDate(val);
|
let d = Zotero.Date.isoToDate(val);
|
||||||
if (!d) {
|
if (!d) {
|
||||||
Zotero.logError("Discarding invalid " + field + " '" + val
|
Zotero.logError(`Discarding invalid ${field} '${val}' for item ${this.libraryKey}`);
|
||||||
+ "' for item " + this.libraryKey);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
val = Zotero.Date.dateToSQL(d, true);
|
val = Zotero.Date.dateToSQL(d, true);
|
||||||
}
|
}
|
||||||
if (field == 'accessDate') {
|
this[field] = val;
|
||||||
this.setField(field, val);
|
|
||||||
setFields[field] = true;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this[field] = val;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'parentItem':
|
case 'parentItem':
|
||||||
|
|
|
@ -1433,6 +1433,20 @@ describe("Zotero.Item", function () {
|
||||||
assert.equal(item.dateModified, '2015-06-07 20:58:00');
|
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* () {
|
it("should ignore non–ISO 8601 dates", function* () {
|
||||||
var json = {
|
var json = {
|
||||||
itemType: "journalArticle",
|
itemType: "journalArticle",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue