Restore 'yesterday'/'today'/'tomorrow' parsing for dates in searches
Follow-up to a549a64de9
, which removed it from strToDate()
This commit is contained in:
parent
c67e29adc7
commit
bbbd02444b
2 changed files with 36 additions and 1 deletions
|
@ -1390,7 +1390,21 @@ Zotero.Search.prototype._buildQuery = Zotero.Promise.coroutine(function* () {
|
||||||
|
|
||||||
if (parseDate){
|
if (parseDate){
|
||||||
var go = false;
|
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
|
// Search on SQL date -- underscore is
|
||||||
// single-character wildcard
|
// single-character wildcard
|
||||||
|
|
|
@ -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 () {
|
describe("fileTypeID", function () {
|
||||||
it("should search by attachment file type", function* () {
|
it("should search by attachment file type", function* () {
|
||||||
let s = new Zotero.Search();
|
let s = new Zotero.Search();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue