diff --git a/jrnl/jrnl.py b/jrnl/jrnl.py index 5553ea73..1c0b97e9 100644 --- a/jrnl/jrnl.py +++ b/jrnl/jrnl.py @@ -187,12 +187,6 @@ def search_mode(args: "Namespace", journal: Journal, **kwargs) -> None: if args.edit: # If we want to both edit and change time in one action if args.change_time: - if not journal: - # --edit can be called on an empty journal, but --edit - # and --change-time together means the user is likely - # expecting to have selected some entries; bail out - return - # Generate a new list instead of assigning so it won't be # modified by _change_time_search_results selected_entries = [e for e in journal.entries] @@ -210,9 +204,7 @@ def search_mode(args: "Namespace", journal: Journal, **kwargs) -> None: _edit_search_results(**kwargs) elif not journal: - # Bail out if there are no entries and we're not editing; we - # could put this before the above edit block, but there are - # some use cases where --edit is called on an empty journal + # Bail out if there are no entries and we're not editing return elif args.change_time: @@ -445,16 +437,15 @@ def _change_time_search_results( MsgText.ChangeTimeEntryQuestion ) - if entries_to_change: - other_entries += [e for e in journal.entries if e not in entries_to_change] - journal.entries = entries_to_change + other_entries += [e for e in journal.entries if e not in entries_to_change] + journal.entries = entries_to_change - date = time.parse(args.change_time) - journal.change_date_entries(date) + date = time.parse(args.change_time) + journal.change_date_entries(date) - journal.entries += other_entries - journal.sort() - journal.write() + journal.entries += other_entries + journal.sort() + journal.write() def _display_search_results(args: "Namespace", journal: Journal, **kwargs) -> None: diff --git a/tests/bdd/features/change_time.feature b/tests/bdd/features/change_time.feature index 17c62688..5f6d419c 100644 --- a/tests/bdd/features/change_time.feature +++ b/tests/bdd/features/change_time.feature @@ -243,17 +243,19 @@ Feature: Change entry times in journal # | basic_dayone.yaml | @todo - Scenario Outline: --change-time with --edit and no selected entries doesn't overwrite journal + Scenario Outline: --change-time with --edit and an empty search adds an entry Given we use the config "" And we write nothing to the editor if opened And we use the password "test" if prompted - When we run "jrnl -on tomorrow --change-time '2022-04-23 10:30' --edit" - #Then the error output should contain "No entry to modify" + And we append to the editor if opened + [2022-11-13 11:25] worked on jrnl tests + When we run "jrnl -on tomorrow --change-time --edit" When we run "jrnl -99 --short" Then the output should be 2020-08-29 11:11 Entry the first. 2020-08-31 14:32 A second entry in what I hope to be a long series. 2020-09-24 09:14 The third entry finally after weeks without writing. + 2022-11-13 11:25 worked on jrnl tests Examples: Configs | config_file |