mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-31 14:33:54 -04:00
Fix failing test comparing date searching with old and new dbs
Ensure date comparison is done in the same timezone. This change only affects legacy code path that is not actually used anywhere other than for tests.
This commit is contained in:
parent
ff1df09c4a
commit
813db96cd3
@ -293,8 +293,7 @@ class ReadingTest(BaseTest):
|
|||||||
old = LibraryDatabase2(self.library_path)
|
old = LibraryDatabase2(self.library_path)
|
||||||
oldvals = {query:set(old.search_getting_ids(query, '')) for query in (
|
oldvals = {query:set(old.search_getting_ids(query, '')) for query in (
|
||||||
# Date tests
|
# Date tests
|
||||||
# 'date:9/6/2011',
|
'date:9/6/2011', 'date:true', 'date:false', 'pubdate:1/9/2011',
|
||||||
'date:true', 'date:false', 'pubdate:1/9/2011',
|
|
||||||
'#date:true', 'date:<100_daysago', 'date:>9/6/2011',
|
'#date:true', 'date:<100_daysago', 'date:>9/6/2011',
|
||||||
'#date:>9/1/2011', '#date:=2011',
|
'#date:>9/1/2011', '#date:=2011',
|
||||||
|
|
||||||
|
@ -293,6 +293,8 @@ class ResultCache(SearchQueryParser): # {{{
|
|||||||
will almost never be correct.
|
will almost never be correct.
|
||||||
'''
|
'''
|
||||||
def relop_eq(db, query, field_count):
|
def relop_eq(db, query, field_count):
|
||||||
|
if db.tzinfo != query.tzinfo:
|
||||||
|
db = db.astimezone(tz=query.tzinfo)
|
||||||
if db.year == query.year:
|
if db.year == query.year:
|
||||||
if field_count == 1:
|
if field_count == 1:
|
||||||
return True
|
return True
|
||||||
@ -303,6 +305,8 @@ class ResultCache(SearchQueryParser): # {{{
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def relop_gt(db, query, field_count):
|
def relop_gt(db, query, field_count):
|
||||||
|
if db.tzinfo != query.tzinfo:
|
||||||
|
db = db.astimezone(tz=query.tzinfo)
|
||||||
if db.year > query.year:
|
if db.year > query.year:
|
||||||
return True
|
return True
|
||||||
if field_count > 1 and db.year == query.year:
|
if field_count > 1 and db.year == query.year:
|
||||||
@ -312,6 +316,8 @@ class ResultCache(SearchQueryParser): # {{{
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def relop_lt(db, query, field_count):
|
def relop_lt(db, query, field_count):
|
||||||
|
if db.tzinfo != query.tzinfo:
|
||||||
|
db = db.astimezone(tz=query.tzinfo)
|
||||||
if db.year < query.year:
|
if db.year < query.year:
|
||||||
return True
|
return True
|
||||||
if field_count > 1 and db.year == query.year:
|
if field_count > 1 and db.year == query.year:
|
||||||
@ -321,12 +327,18 @@ class ResultCache(SearchQueryParser): # {{{
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def relop_ne(db, query, field_count):
|
def relop_ne(db, query, field_count):
|
||||||
|
if db.tzinfo != query.tzinfo:
|
||||||
|
db = db.astimezone(tz=query.tzinfo)
|
||||||
return not relop_eq(db, query, field_count)
|
return not relop_eq(db, query, field_count)
|
||||||
|
|
||||||
def relop_ge(db, query, field_count):
|
def relop_ge(db, query, field_count):
|
||||||
|
if db.tzinfo != query.tzinfo:
|
||||||
|
db = db.astimezone(tz=query.tzinfo)
|
||||||
return not relop_lt(db, query, field_count)
|
return not relop_lt(db, query, field_count)
|
||||||
|
|
||||||
def relop_le(db, query, field_count):
|
def relop_le(db, query, field_count):
|
||||||
|
if db.tzinfo != query.tzinfo:
|
||||||
|
db = db.astimezone(tz=query.tzinfo)
|
||||||
return not relop_gt(db, query, field_count)
|
return not relop_gt(db, query, field_count)
|
||||||
|
|
||||||
self.date_search_relops = {
|
self.date_search_relops = {
|
||||||
@ -417,7 +429,7 @@ class ResultCache(SearchQueryParser): # {{{
|
|||||||
continue
|
continue
|
||||||
v = item[loc]
|
v = item[loc]
|
||||||
if isinstance(v, (bytes, str)):
|
if isinstance(v, (bytes, str)):
|
||||||
v = parse_date(v)
|
v = parse_date(v, as_utc=False)
|
||||||
if relop(v, qd, field_count):
|
if relop(v, qd, field_count):
|
||||||
matches.add(item[0])
|
matches.add(item[0])
|
||||||
return matches
|
return matches
|
||||||
|
Loading…
x
Reference in New Issue
Block a user