Allow "now" in Accessed field to use current time

Closes #1340
This commit is contained in:
Dan Stillman 2018-01-05 03:40:57 -05:00
parent 5847388862
commit 3f6ef7fb01
2 changed files with 26 additions and 1 deletions

View file

@ -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', '');
}

View file

@ -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
);
});
})