- Fix autocomplete date searches (broken since autocomplete speedup)
- Fix search for January dates - Support 'yesterday'/'today'/'tomorrow' and localized equivalents (case-insensitive) in date searches (e.g., [Date Added] [is] ['yesterday'])
This commit is contained in:
parent
6cefc8fb72
commit
8560710463
3 changed files with 42 additions and 9 deletions
|
@ -1314,7 +1314,35 @@ Zotero.Search.prototype._buildQuery = function(){
|
|||
|
||||
if (parseDate){
|
||||
var go = false;
|
||||
var dateparts = Zotero.Date.strToDate(condition['value']);
|
||||
// Allow 'today' or localized 'today'
|
||||
var lc = (condition.value + '').toLowerCase();
|
||||
if (lc == 'yesterday' || lc == Zotero.getString('date.yesterday')) {
|
||||
var dateparts = Zotero.Date.strToDate(
|
||||
Zotero.Date.dateToSQL(
|
||||
new Date(new Date().getTime() - 86400000), true
|
||||
)
|
||||
);
|
||||
dateparts.part = null;
|
||||
}
|
||||
else if (lc == 'today' || lc == Zotero.getString('date.today')) {
|
||||
var dateparts = Zotero.Date.strToDate(
|
||||
Zotero.Date.dateToSQL(
|
||||
new Date(), true
|
||||
)
|
||||
);
|
||||
dateparts.part = null;
|
||||
}
|
||||
else if (lc == 'tomorrow' || lc == Zotero.getString('date.tomorrow')) {
|
||||
var dateparts = Zotero.Date.strToDate(
|
||||
Zotero.Date.dateToSQL(
|
||||
new Date(new Date().getTime() + 86400000), true
|
||||
)
|
||||
);
|
||||
dateparts.part = null;
|
||||
}
|
||||
else {
|
||||
var dateparts = Zotero.Date.strToDate(condition.value);
|
||||
}
|
||||
|
||||
// Search on SQL date -- underscore is
|
||||
// single-character wildcard
|
||||
|
@ -1322,14 +1350,14 @@ Zotero.Search.prototype._buildQuery = function(){
|
|||
// If isBefore or isAfter, month and day fall back
|
||||
// to '00' so that a search for just a year works
|
||||
// (and no year will just not find anything)
|
||||
var sqldate = dateparts['year'] ?
|
||||
utils.lpad(dateparts['year'], '0', 4) : '____';
|
||||
var sqldate = dateparts.year ?
|
||||
utils.lpad(dateparts.year, '0', 4) : '____';
|
||||
sqldate += '-'
|
||||
sqldate += dateparts['month'] ?
|
||||
utils.lpad(dateparts['month'] + 1, '0', 2) : alt;
|
||||
sqldate += dateparts.month || dateparts.month === 0 ?
|
||||
utils.lpad(dateparts.month + 1, '0', 2) : alt;
|
||||
sqldate += '-';
|
||||
sqldate += dateparts['day'] ?
|
||||
utils.lpad(dateparts['day'], '0', 2) : alt;
|
||||
sqldate += dateparts.day ?
|
||||
utils.lpad(dateparts.day, '0', 2) : alt;
|
||||
|
||||
if (sqldate!='____-__-__'){
|
||||
go = true;
|
||||
|
|
|
@ -513,6 +513,9 @@ date.daySuffixes = st, nd, rd, th
|
|||
date.abbreviation.year = y
|
||||
date.abbreviation.month = m
|
||||
date.abbreviation.day = d
|
||||
date.yesterday = yesterday
|
||||
date.today = today
|
||||
date.tomorrow = tomorrow
|
||||
|
||||
citation.multipleSources = Multiple Sources...
|
||||
citation.singleSource = Single Source...
|
||||
|
|
|
@ -163,7 +163,8 @@ ZoteroAutoComplete.prototype.startSearch = function(searchString, searchParam, p
|
|||
case 'dateAdded':
|
||||
var sql = "SELECT DISTINCT DATE(" + searchParam + ", 'localtime') AS val, NULL AS comment FROM items "
|
||||
+ "WHERE " + searchParam + " LIKE ? ORDER BY " + searchParam;
|
||||
statement = this._zotero.DB.getStatement(sql, searchString + '%');
|
||||
var sqlParams = [searchString + '%'];
|
||||
statement = this._zotero.DB.getStatement(sql, sqlParams);
|
||||
break;
|
||||
|
||||
case 'accessDate':
|
||||
|
@ -171,7 +172,8 @@ ZoteroAutoComplete.prototype.startSearch = function(searchString, searchParam, p
|
|||
|
||||
var sql = "SELECT DISTINCT DATE(value, 'localtime') AS val, NULL AS comment FROM itemData "
|
||||
+ "WHERE fieldID=? AND value LIKE ? ORDER BY value";
|
||||
statement = this._zotero.DB.getStatement(sql, [fieldID, searchString + '%']);
|
||||
var sqlParams = [fieldID, searchString + '%'];
|
||||
statement = this._zotero.DB.getStatement(sql, sqlParams);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
Loading…
Reference in a new issue