www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit 8560710463d22e6700681762052841a7b6d10397
parent 6cefc8fb729d27e43d42800dac196c0ed21a1ee2
Author: Dan Stillman <dstillman@zotero.org>
Date:   Tue, 12 Jan 2010 23:06:26 +0000

- 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'])


Diffstat:
Mchrome/content/zotero/xpcom/search.js | 42+++++++++++++++++++++++++++++++++++-------
Mchrome/locale/en-US/zotero/zotero.properties | 3+++
Mcomponents/zotero-autocomplete.js | 6++++--
3 files changed, 42 insertions(+), 9 deletions(-)

diff --git a/chrome/content/zotero/xpcom/search.js b/chrome/content/zotero/xpcom/search.js @@ -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; diff --git a/chrome/locale/en-US/zotero/zotero.properties b/chrome/locale/en-US/zotero/zotero.properties @@ -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... diff --git a/components/zotero-autocomplete.js b/components/zotero-autocomplete.js @@ -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: