From 366c6ca2488215c8d38fed0d25257a11b2ad44d6 Mon Sep 17 00:00:00 2001 From: Stephan Gabler Date: Mon, 21 May 2012 20:55:45 +0200 Subject: [PATCH] fix date parsing when text body contains colon. The problem was appeared when no date was specified and the text body contained a colon. All the text before the colon was discarded and lost. This commit changes the code to first extract the first line as a title and then only look whether this title contains a valid date. --- jrnl.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/jrnl.py b/jrnl.py index ceace6e9..429f0c6a 100755 --- a/jrnl.py +++ b/jrnl.py @@ -323,17 +323,8 @@ class Journal: def new_entry(self, raw, date=None): """Constructs a new entry from some raw text input. If a date is given, it will parse and use this, otherwise scan for a date in the input first.""" - if not date: - if raw.find(":") > 0: - date = self.parse_date(raw[:raw.find(":")]) - if date: # Parsed successfully, strip that from the raw text - raw = raw[raw.find(":")+1:].strip() - - if not date: # Still nothing? Meh, just live in the moment. - date = self.parse_date("now") # Split raw text into title and body - body = "" title_end = len(raw) for separator in ".?!": sep_pos = raw.find(separator) @@ -341,6 +332,15 @@ class Journal: title_end = sep_pos title = raw[:title_end+1] body = raw[title_end+1:].strip() + + if not date: + if title.find(":") > 0: + date = self.parse_date(title[:title.find(":")]) + if date: # Parsed successfully, strip that from the raw text + title = title[title.find(":")+1:].strip() + if not date: # Still nothing? Meh, just live in the moment. + date = self.parse_date("now") + self.entries.append(Entry(self, date, title, body)) self.sort()