From 4bdcdd33f643b6947e90aaa2bf1bdc69ca1837d3 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Tue, 12 Jan 2010 23:06:26 +0000 Subject: [PATCH] - 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']) --- chrome/content/zotero/xpcom/search.js | 42 ++++++++++++++++---- chrome/locale/en-US/zotero/zotero.properties | 3 ++ components/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 index 6bda046453..a32e3c7f04 100644 --- 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 index bfb4e43924..822423026c 100644 --- 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 index c6a7b75a5d..73dbf287df 100644 --- 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: