mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-06-28 21:46:13 +02:00
Add new -today-in-history
, -month
, -day
, and -year
search filters (#1145)
* Introduce -reminisce, -month, -day, and -year * Update expected_args in parse_args tests * Add check before creating compare_d * Misc changes * Implement testing for -month, -day, -year, and -reminisce * Compress tests into one Scenario Outline * Fix failing tests by updating dates_similar journal * Create 'we set current date and time to' step * Use time.parse in reminisce * Update dates_similar journal * Make 'Searching in a journal' test shorter * Lint * Implement reminiscing test * Add combination tests * Finalize tests * Finalize pytests * Simplify reminisce tests * Change reminsice help (since it also shows today's entries) * Re-do tests; use various tests * Remove old test data * Better scenario description * Standardize format for compare_d * Rename -reminisce to -today-in-history
This commit is contained in:
parent
18058c74e5
commit
f0e8fa2060
6 changed files with 184 additions and 0 deletions
|
@ -189,6 +189,9 @@ class Journal:
|
|||
def filter(
|
||||
self,
|
||||
tags=[],
|
||||
month=None,
|
||||
day=None,
|
||||
year=None,
|
||||
start_date=None,
|
||||
end_date=None,
|
||||
starred=False,
|
||||
|
@ -220,11 +223,19 @@ class Journal:
|
|||
if contains:
|
||||
contains_lower = contains.casefold()
|
||||
|
||||
# Create datetime object for comparison below
|
||||
# this approach allows various formats
|
||||
if month or day or year:
|
||||
compare_d = time.parse(f"{month or 1}.{day or 1}.{year or 1}")
|
||||
|
||||
result = [
|
||||
entry
|
||||
for entry in self.entries
|
||||
if (not tags or tagged(entry.tags))
|
||||
and (not starred or entry.starred)
|
||||
and (not month or entry.date.month == compare_d.month)
|
||||
and (not day or entry.date.day == compare_d.day)
|
||||
and (not year or entry.date.year == compare_d.year)
|
||||
and (not start_date or entry.date >= start_date)
|
||||
and (not end_date or entry.date <= end_date)
|
||||
and (not exclude or not excluded(entry.tags))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue