diff --git a/chrome/content/zotero/bindings/itembox.xml b/chrome/content/zotero/bindings/itembox.xml index ee63273f21..4dd094e1bd 100644 --- a/chrome/content/zotero/bindings/itembox.xml +++ b/chrome/content/zotero/bindings/itembox.xml @@ -1920,6 +1920,9 @@ if (value != '') { switch (fieldName) { case 'accessDate': + // Parse 'yesterday'/'today'/'tomorrow' + value = Zotero.Date.parseDescriptiveString(value); + // Allow "now" to use current time if (value == 'now') { value = Zotero.Date.dateToSQL(new Date(), true); @@ -1964,18 +1967,8 @@ default: // TODO: generalize to all date rows/fields if (Zotero.ItemFields.isFieldOfBase(fieldName, 'date')) { - // Parse 'yesterday'/'today'/'tomorrow' and convert to dates, - // since it doesn't make sense for those to be actual metadata values - var lc = value.toLowerCase(); - if (lc == 'yesterday' || lc == Zotero.getString('date.yesterday')) { - value = Zotero.Date.dateToSQL(new Date(new Date().getTime() - 86400000)).substr(0, 10); - } - else if (lc == 'today' || lc == Zotero.getString('date.today')) { - value = Zotero.Date.dateToSQL(new Date()).substr(0, 10); - } - else if (lc == 'tomorrow' || lc == Zotero.getString('date.tomorrow')) { - value = Zotero.Date.dateToSQL(new Date(new Date().getTime() + 86400000)).substr(0, 10); - } + // Parse 'yesterday'/'today'/'tomorrow' + value = Zotero.Date.parseDescriptiveString(value); } } } diff --git a/chrome/content/zotero/xpcom/date.js b/chrome/content/zotero/xpcom/date.js index 91fb8018ba..a609181f2a 100644 --- a/chrome/content/zotero/xpcom/date.js +++ b/chrome/content/zotero/xpcom/date.js @@ -708,6 +708,29 @@ Zotero.Date = new function(){ } + /** + * Convert 'yesterday'/'today'/'tomorrow' to SQL date, or else return original string + * + * @param {String} str + * @return {String} + */ + this.parseDescriptiveString = function (str) { + // Parse 'yesterday'/'today'/'tomorrow' and convert to dates, + // since it doesn't make sense for those to be actual metadata values + var lc = str.toLowerCase().trim(); + if (lc == 'yesterday' || lc == Zotero.getString('date.yesterday')) { + str = Zotero.Date.dateToSQL(new Date(new Date().getTime() - 86400000)).substr(0, 10); + } + else if (lc == 'today' || lc == Zotero.getString('date.today')) { + str = Zotero.Date.dateToSQL(new Date()).substr(0, 10); + } + else if (lc == 'tomorrow' || lc == Zotero.getString('date.tomorrow')) { + str = Zotero.Date.dateToSQL(new Date(new Date().getTime() + 86400000)).substr(0, 10); + } + return str; + }; + + function isSQLDate(str, allowZeroes) { if (allowZeroes) { return _sqldateWithZeroesRE.test(str);