From bbbd02444b626a5b66849b3687f9daa2528ac28d Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Fri, 6 Dec 2019 03:12:10 -0700 Subject: [PATCH] Restore 'yesterday'/'today'/'tomorrow' parsing for dates in searches Follow-up to a549a64de93, which removed it from strToDate() --- chrome/content/zotero/xpcom/data/search.js | 16 +++++++++++++++- test/tests/searchTest.js | 21 +++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/chrome/content/zotero/xpcom/data/search.js b/chrome/content/zotero/xpcom/data/search.js index 79eb45a900..3faa42ecaf 100644 --- a/chrome/content/zotero/xpcom/data/search.js +++ b/chrome/content/zotero/xpcom/data/search.js @@ -1390,7 +1390,21 @@ Zotero.Search.prototype._buildQuery = Zotero.Promise.coroutine(function* () { if (parseDate){ var go = false; - var dateparts = Zotero.Date.strToDate(condition.value); + let value = condition.value; + + // Parse 'yesterday'/'today'/'tomorrow' + let lc = value.toLowerCase(); + if (lc == 'yesterday' || lc == Zotero.getString('date.yesterday')) { + value = Zotero.Date.dateToSQL(new Date(Date.now() - 1000 * 60 * 60 * 24)).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(Date.now() + 1000 * 60 * 60 * 24)).substr(0, 10); + } + + let dateparts = Zotero.Date.strToDate(value); // Search on SQL date -- underscore is // single-character wildcard diff --git a/test/tests/searchTest.js b/test/tests/searchTest.js index d9caf0a924..6ad17cc72e 100644 --- a/test/tests/searchTest.js +++ b/test/tests/searchTest.js @@ -218,6 +218,27 @@ describe("Zotero.Search", function() { }); }); + describe("dateAdded", function () { + it("should handle 'today'", async function () { + var item = await createDataObject('item'); + + var s = new Zotero.Search(); + s.libraryID = item.libraryID; + s.name = "Test"; + s.addCondition('dateAdded', 'is', 'today'); + var matches = await s.search(); + assert.includeMembers(matches, [item.id]); + + // Make sure 'yesterday' doesn't match + s = new Zotero.Search(); + s.libraryID = item.libraryID; + s.name = "Test"; + s.addCondition('dateAdded', 'is', 'yesterday'); + matches = await s.search(); + assert.lengthOf(matches, 0); + }); + }); + describe("fileTypeID", function () { it("should search by attachment file type", function* () { let s = new Zotero.Search();