From 6673c64ac651c94637f126be63b9f2a3e5ab9776 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Sat, 19 Aug 2017 15:21:57 +0200 Subject: [PATCH] Fix accessDate when translators set CURRENT_TIMESTAMP (But it also seems like we always do that automatically for web translators, so I'm not sure why so many translators set that.) --- .../zotero/xpcom/translation/translate_item.js | 4 ++++ test/tests/translateTest.js | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/chrome/content/zotero/xpcom/translation/translate_item.js b/chrome/content/zotero/xpcom/translation/translate_item.js index 2b4a3021e..0ceddc800 100644 --- a/chrome/content/zotero/xpcom/translation/translate_item.js +++ b/chrome/content/zotero/xpcom/translation/translate_item.js @@ -107,6 +107,10 @@ Zotero.Translate.ItemSaver.prototype = { newItem.libraryID = this._libraryID; if (item.creators) this._cleanCreators(item.creators); if(item.tags) item.tags = this._cleanTags(item.tags); + + if (item.accessDate == 'CURRENT_TIMESTAMP') { + item.accessDate = Zotero.Date.dateToISO(new Date()); + } // Need to handle these specially. Put them in a separate object to // avoid a warning from fromJSON() diff --git a/test/tests/translateTest.js b/test/tests/translateTest.js index 3aa6dfd1f..8229c17ba 100644 --- a/test/tests/translateTest.js +++ b/test/tests/translateTest.js @@ -400,6 +400,20 @@ describe("Zotero.Translate", function() { assert.isAbove(delta, -500); assert.isBelow(delta, 5000); }); + + it('web translators should set accessDate to current date for CURRENT_TIMESTAMP', function* () { + let myItem = { + itemType: "webpage", + title: "Test Item", + url: "https://www.zotero.org/", + accessDate: 'CURRENT_TIMESTAMP' + }; + let newItems = yield saveItemsThroughTranslator("web", [myItem]); + let currentDate = new Date(); + let delta = currentDate - Zotero.Date.sqlToDate(newItems[0].getField("accessDate"), true); + assert.isAbove(delta, -500); + assert.isBelow(delta, 5000); + }); it('web translators should save attachments', function* () { let myItems = [