mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-07-04 15:36:14 +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
ef23d7eabe
commit
1fa851ed0c
7 changed files with 93 additions and 2 deletions
|
@ -122,7 +122,11 @@ class Journal(object):
|
|||
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