From 4dbdc7032d9c5dbf4c66bcf08c6142027f129d8b Mon Sep 17 00:00:00 2001 From: Manuel Ebert Date: Mon, 21 Jul 2014 17:33:30 +0900 Subject: [PATCH 1/3] Don't correct future timestamps if year is present in input --- jrnl/time.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/jrnl/time.py b/jrnl/time.py index 41503517..531293de 100644 --- a/jrnl/time.py +++ b/jrnl/time.py @@ -3,8 +3,9 @@ from dateutil.parser import parse as dateparse try: import parsedatetime.parsedatetime_consts as pdt except ImportError: import parsedatetime as pdt -DEFAULT_FUTURE = datetime(datetime.now().year, 12, 31, 23, 59, 59) -DEFAULT_PAST = datetime(datetime.now().year, 1, 1, 0, 0) +FAKE_YEAR = 9999 +DEFAULT_FUTURE = datetime(FAKE_YEAR, 12, 31, 23, 59, 59) +DEFAULT_PAST = datetime(FAKE_YEAR, 1, 1, 0, 0) consts = pdt.Constants(usePyICU=False) consts.DOWParseStyle = -1 # "Monday" will be either today or the last Monday @@ -20,9 +21,14 @@ def parse(date_str, inclusive=False, default_hour=None, default_minute=None): default_date = DEFAULT_FUTURE if inclusive else DEFAULT_PAST date = None + year_present = False while not date: try: date = dateparse(date_str, default=default_date) + if date.year == FAKE_YEAR: + date = datetime(datetime.now().year, date.timetuple()[1:6]) + else: + year_present = True flag = 1 if date.hour == date.minute == 0 else 2 date = date.timetuple() except Exception as e: @@ -50,6 +56,6 @@ def parse(date_str, inclusive=False, default_hour=None, default_minute=None): # Rather then this, we would like to see parsedatetime patched so we can tell it to prefer # past dates dt = datetime.now() - date - if dt.days < -28: + if dt.days < -28 and not year_present: date = date.replace(date.year - 1) return date From 286366ae856e9f58b7be7b3d921dbbf31a5020f7 Mon Sep 17 00:00:00 2001 From: Manuel Ebert Date: Mon, 21 Jul 2014 17:33:39 +0900 Subject: [PATCH 2/3] Regression test for future timestamps --- features/regression.feature | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/features/regression.feature b/features/regression.feature index ad52e2c4..1672afb4 100644 --- a/features/regression.feature +++ b/features/regression.feature @@ -21,6 +21,13 @@ Feature: Zapped bugs should stay dead. Then we should see the message "Entry added" and the journal should contain "2013-11-30 15:42 Project Started." + Scenario: Date in the future should be parsed correctly + # https://github.com/maebert/jrnl/issues/185 + Given we use the config "basic.json" + When we run "jrnl 26/06/2019: Planet? Earth. Year? 2019." + Then we should see the message "Entry added" + and the journal should contain "2019-06-26 09:00 Planet?" + Scenario: Loading entry with ambiguous time stamp #https://github.com/maebert/jrnl/issues/153 Given we use the config "bug153.json" @@ -31,24 +38,24 @@ Feature: Zapped bugs should stay dead. 2013-10-27 03:27 Some text. """ - Scenario: Title with an embedded period. + Scenario: Title with an embedded period. Given we use the config "basic.json" When we run "jrnl 04-24-2014: Created a new website - empty.com. Hope to get a lot of traffic." Then we should see the message "Entry added" When we run "jrnl -1" - Then the output should be + Then the output should be """ 2014-04-24 09:00 Created a new website - empty.com. | Hope to get a lot of traffic. """ - + Scenario: Title with an embedded period on DayOne journal Given we use the config "dayone.json" When we run "jrnl 04-24-2014: Ran 6.2 miles today in 1:02:03. I'm feeling sore because I forgot to stretch." Then we should see the message "Entry added" When we run "jrnl -1" - Then the output should be + Then the output should be """ 2014-04-24 09:00 Ran 6.2 miles today in 1:02:03. | I'm feeling sore because I forgot to stretch. - """ \ No newline at end of file + """ From 28dcb3ab9063a2aef1d67bc143f92dc96ad4abc2 Mon Sep 17 00:00:00 2001 From: Manuel Ebert Date: Mon, 21 Jul 2014 17:33:44 +0900 Subject: [PATCH 3/3] Version bump --- CHANGELOG.md | 1 + jrnl/__init__.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c8c12a17..4899a90b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ Changelog ### 1.9 (July 21, 2014) +* __1.9.1__ Fixed: Dates in the future can be parsed as well. * __1.9.0__ Improved: Greatly improved date parsing. Also added an `-on` option for filtering ### 1.8 (May 22, 2014) diff --git a/jrnl/__init__.py b/jrnl/__init__.py index b68d8ee8..0c557a82 100644 --- a/jrnl/__init__.py +++ b/jrnl/__init__.py @@ -8,7 +8,7 @@ jrnl is a simple journal application for your command line. from __future__ import absolute_import __title__ = 'jrnl' -__version__ = '1.9.0' +__version__ = '1.9.1' __author__ = 'Manuel Ebert' __license__ = 'MIT License' __copyright__ = 'Copyright 2013 - 2014 Manuel Ebert'