Introduce -reminisce, -month, -day, and -year

This commit is contained in:
karimpwnz 2021-01-03 19:46:26 +02:00
parent c155bafa84
commit f19ae0be86
3 changed files with 47 additions and 0 deletions

View file

@ -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,18 @@ class Journal:
if contains:
contains_lower = contains.casefold()
# Create datetime object for comparison below
# this approach allows different month formats
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))

View file

@ -176,6 +176,30 @@ def parse_args(args=[]):
reading.add_argument(
"-on", dest="on_date", metavar="DATE", help="Show entries on this date"
)
reading.add_argument(
"-reminisce",
dest="reminisce",
action="store_true",
help="Show entries of today in previous years",
)
reading.add_argument(
"-month",
dest="month",
metavar="DATE",
help="Show entries on this month of any year",
)
reading.add_argument(
"-day",
dest="day",
metavar="DATE",
help="Show entries on this day of any month",
)
reading.add_argument(
"-year",
dest="year",
metavar="DATE",
help="Show entries on this year",
)
reading.add_argument(
"-from",
dest="start_date",

View file

@ -15,6 +15,7 @@ from .config import get_config_path
from .editor import get_text_from_editor
from .editor import get_text_from_stdin
from .exception import UserAbort
from datetime import datetime
def run(args):
@ -77,6 +78,10 @@ def _is_write_mode(args, config, **kwargs):
args.edit,
args.export,
args.end_date,
args.reminisce,
args.month,
args.day,
args.year,
args.limit,
args.on_date,
args.short,
@ -206,8 +211,16 @@ def _search_journal(args, journal, **kwargs):
if args.on_date:
args.start_date = args.end_date = args.on_date
if args.reminisce:
today = datetime.today()
args.day = today.day
args.month = today.month
journal.filter(
tags=args.text,
month=args.month,
day=args.day,
year=args.year,
start_date=args.start_date,
end_date=args.end_date,
strict=args.strict,