mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-06-28 21:46:13 +02:00
Fix handling of little-endian date format
Ever since version 2.0, when parsing a journal file, jrnl would not use the custom date format string anymore. Instead, it relied on the dateutil library to get the parsing right. This change was made to allow people to change their date format without having to manually change their file. However, this broke some existing date formats like %d.%m.%Y, as it would falsely interpret the month as day and vice versa. This commit adds some tests to catch this error and fixes it by trying to parse the dates using the custom format first, only falling back to dateutil when needed.
This commit is contained in:
parent
9d8d6a83ae
commit
7f46d1a40a
7 changed files with 92 additions and 1 deletions
|
@ -119,7 +119,11 @@ class Journal:
|
|||
last_entry_pos = 0
|
||||
for match in date_blob_re.finditer(journal_txt):
|
||||
date_blob = match.groups()[0]
|
||||
new_date = time.parse(date_blob)
|
||||
try:
|
||||
new_date = datetime.strptime(date_blob, self.config["timeformat"])
|
||||
except ValueError:
|
||||
new_date = time.parse(date_blob)
|
||||
|
||||
if new_date:
|
||||
if entries:
|
||||
entries[-1].text = journal_txt[last_entry_pos:match.start()]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue