This commit is contained in:
Christian Wutte 2025-04-29 11:53:24 +02:00 committed by GitHub
commit 3d3ade2b26
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 65 additions and 2 deletions

View file

@ -187,6 +187,7 @@ class Journal:
new_date = time.parse(date_blob, bracketed=True) new_date = time.parse(date_blob, bracketed=True)
if new_date: if new_date:
# Fill in text of entry created in previous loop
if entries: if entries:
entries[-1].text = journal_txt[last_entry_pos : match.start()] entries[-1].text = journal_txt[last_entry_pos : match.start()]
last_entry_pos = match.end() last_entry_pos = match.end()
@ -376,7 +377,29 @@ class Journal:
) )
if date: # Parsed successfully, strip that from the raw text if date: # Parsed successfully, strip that from the raw text
starred = raw[:colon_pos].strip().endswith("*") starred = raw[:colon_pos].strip().endswith("*")
raw = raw[colon_pos + 1 :].strip() raw = raw[(colon_pos + 1):].strip()
else:
date_blob_re = re.compile("(?:^|\n)\\[([^\\]]+)\\] ")
match = date_blob_re.search(raw)
if match is not None:
date_blob = match.groups()[0]
try:
date = datetime.datetime.strptime(
date_blob, self.config["timeformat"]
)
except ValueError:
# Passing in a date that had brackets around it
date = time.parse(
date_blob,
bracketed=True,
default_hour=self.config["default_hour"],
default_minute=self.config["default_minute"],
)
if date: # Parsed successfully, strip that from the raw text
starred = raw[:match.start()].strip().endswith("*")
raw = raw[match.end():].strip()
starred = ( starred = (
starred starred
or first_line.startswith("*") or first_line.startswith("*")

View file

@ -53,6 +53,13 @@ Feature: Reading and writing to journal with custom date formats
| little_endian_dates.yaml | 2032-02-01: Test. | 01.02.2032 09:00 Test. | | little_endian_dates.yaml | 2032-02-01: Test. | 01.02.2032 09:00 Test. |
| little_endian_dates.yaml | 2020-01-01: Test. | 01.01.2020 09:00 Test. | | little_endian_dates.yaml | 2020-01-01: Test. | 01.01.2020 09:00 Test. |
| little_endian_dates.yaml | 2020-12-31: Test. | 31.12.2020 09:00 Test. | | little_endian_dates.yaml | 2020-12-31: Test. | 31.12.2020 09:00 Test. |
# @todo: is it fine that default time be used here and not 00:00?
| little_endian_dates.yaml | [2020-12-31] bracket. | 31.12.2020 09:00 bracket. |
| little_endian_dates.yaml | [2020-12-31 10:00 PM] brkt. | 31.12.2020 22:00 brkt. |
| little_endian_dates.yaml | [2020-12-31]: brkt colon. | 31.12.2020 09:00 brkt colon. |
| little_endian_dates.yaml | [2020-12-31 12:34]: b colon. | 31.12.2020 12:34 b colon. |
| little_endian_dates.yaml | [2019-02-29] brkt neg. | [2019-02-29] brkt neg. |
| little_endian_dates.yaml | [2020-08-32] brkt neg. | [2020-08-32] brkt neg. |
Scenario Outline: Searching for dates with custom date Scenario Outline: Searching for dates with custom date
@ -80,6 +87,14 @@ Feature: Reading and writing to journal with custom date formats
Then the output should contain "10.05.2013 09:00 I saw Elvis." Then the output should contain "10.05.2013 09:00 I saw Elvis."
And the output should contain "He's alive." And the output should contain "He's alive."
Scenario: Writing an entry at the prompt with custom date in bracket format
Given we use the config "little_endian_dates.yaml"
When we run "jrnl" and type "[2013-05-10 12:34] I saw Elvis. He's alive."
Then we should get no error
When we run "jrnl -999"
Then the output should contain "10.05.2013 12:34 I saw Elvis."
And the output should contain "He's alive."
Scenario: Viewing today's entries does not print the entire journal Scenario: Viewing today's entries does not print the entire journal
# see: https://github.com/jrnl-org/jrnl/issues/741 # see: https://github.com/jrnl-org/jrnl/issues/741

View file

@ -16,6 +16,31 @@ Feature: Starring entries
| empty_folder.yaml | | empty_folder.yaml |
| dayone.yaml | | dayone.yaml |
Scenario Outline: Starring an entry with bracketed date will mark it in the journal file
Given we use the config "<config_file>"
When we run "jrnl <command>"
Then we should get no error
When we run "jrnl -on 2013-07-20 -starred"
Then the output should contain "2013-07-20 09:00 Best day of my life!"
Examples: configs
| config_file | command |
| simple.yaml | [2013-07-20] Best day of my life! * |
| empty_folder.yaml | [2013-07-20] Best day of my life! * |
# Note: this one fail due to whitespace, cmp. next config
# | dayone.yaml | [2013-07-20] Best day of my life! * |
| dayone.yaml | [2013-07-20] Best day of my life!* |
| simple.yaml | [2013-07-20]*: Best day of my life! |
| empty_folder.yaml | [2013-07-20]*: Best day of my life! |
| dayone.yaml | [2013-07-20]*: Best day of my life! |
| simple.yaml | [2013-07-20] * : Best day of my life! |
| empty_folder.yaml | [2013-07-20] * : Best day of my life! |
| dayone.yaml | [2013-07-20] * : Best day of my life! |
| simple.yaml | [2013-07-20] * Best day of my life! |
| empty_folder.yaml | [2013-07-20] * Best day of my life! |
# Note: this one fails in having the star in the output too
# | dayone.yaml | [2013-07-20] * Best day of my life! |
Scenario Outline: Filtering by starred entries will show only starred entries Scenario Outline: Filtering by starred entries will show only starred entries
Given we use the config "<config_file>" Given we use the config "<config_file>"
When we run "jrnl -starred" When we run "jrnl -starred"