From 3f6ef7fb01f81cef2de78edd11399f7e97c1b232 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Fri, 5 Jan 2018 03:40:57 -0500 Subject: [PATCH] Allow "now" in Accessed field to use current time Closes #1340 --- chrome/content/zotero/bindings/itembox.xml | 6 +++++- test/tests/itemPaneTest.js | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/chrome/content/zotero/bindings/itembox.xml b/chrome/content/zotero/bindings/itembox.xml index fdec1317bf..9639e3cf19 100644 --- a/chrome/content/zotero/bindings/itembox.xml +++ b/chrome/content/zotero/bindings/itembox.xml @@ -1884,8 +1884,12 @@ if (value != '') { switch (fieldName) { case 'accessDate': + // Allow "now" to use current time + if (value == 'now') { + value = Zotero.Date.dateToSQL(new Date(), true); + } // If just date, don't convert to UTC - if (Zotero.Date.isSQLDate(value)) { + else if (Zotero.Date.isSQLDate(value)) { var localDate = Zotero.Date.sqlToDate(value); value = Zotero.Date.dateToSQL(localDate).replace(' 00:00:00', ''); } diff --git a/test/tests/itemPaneTest.js b/test/tests/itemPaneTest.js index e9caab6bb2..081d59fde0 100644 --- a/test/tests/itemPaneTest.js +++ b/test/tests/itemPaneTest.js @@ -110,6 +110,27 @@ describe("Item pane", function () { // Wait for no-op saveTx() yield Zotero.Promise.delay(1); }); + + it("should accept 'now' for Accessed", async function () { + var item = await createDataObject('item'); + + var itemBox = doc.getElementById('zotero-editpane-item-box'); + var box = doc.getAnonymousNodes(itemBox)[0]; + var label = box.querySelector('label[fieldname="accessDate"][class="zotero-clicky"]'); + label.click(); + var textbox = box.querySelector('textbox[fieldname="accessDate"]'); + textbox.value = 'now'; + // Blur events don't necessarily trigger if window doesn't have focus + itemBox.hideEditor(textbox); + + await waitForItemEvent('modify'); + + assert.approximately( + Zotero.Date.sqlToDate(item.getField('accessDate'), true).getTime(), + Date.now(), + 1000 + ); + }); })