From dd91d7a4919ff4e806a0d1b742a6e16b7c8dbe02 Mon Sep 17 00:00:00 2001 From: William Minchin Date: Fri, 7 Feb 2014 10:17:02 -0700 Subject: [PATCH 01/12] add 'from' and 'to' flags to `parse_date` When given a day, allows you to select which end of the day --- jrnl/Journal.py | 16 +++++++---- parse-date-test.py | 67 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 5 deletions(-) create mode 100644 parse-date-test.py diff --git a/jrnl/Journal.py b/jrnl/Journal.py index b5d7a664..a5a345b8 100644 --- a/jrnl/Journal.py +++ b/jrnl/Journal.py @@ -208,8 +208,8 @@ class Journal(object): If strict is True, all tags must be present in an entry. If false, the entry is kept if any tag is present.""" self.search_tags = set([tag.lower() for tag in tags]) - end_date = self.parse_date(end_date) - start_date = self.parse_date(start_date) + end_date = self.parse_date(end_date, end_flag="to") + start_date = self.parse_date(start_date, end_flag="from") # If strict mode is on, all tags have to be present in entry tagged = self.search_tags.issubset if strict else self.search_tags.intersection result = [ @@ -235,7 +235,7 @@ class Journal(object): e.body = '' self.entries = result - def parse_date(self, date_str): + def parse_date(self, date_str, end_flag=None): """Parses a string containing a fuzzy date and returns a datetime.datetime object""" if not date_str: return None @@ -258,8 +258,14 @@ class Journal(object): except TypeError: return None - if flag is 1: # Date found, but no time. Use the default time. - date = datetime(*date[:3], hour=self.config['default_hour'], minute=self.config['default_minute']) + if flag is 1: # Date found, but no time. + if end_flag == "from": + date = datetime(*date[:3], hour=0, minute=0) + elif end_flag == "to": + date = datetime(*date[:3], hour=23, minute=59, second=59) + else: + # Use the default time. + date = datetime(*date[:3], hour=self.config['default_hour'], minute=self.config['default_minute']) else: date = datetime(*date[:6]) diff --git a/parse-date-test.py b/parse-date-test.py new file mode 100644 index 00000000..5ff9e42e --- /dev/null +++ b/parse-date-test.py @@ -0,0 +1,67 @@ +"""Parses a string containing a fuzzy date and returns a datetime.datetime object""" + +from datetime import datetime +import dateutil +import argparse +try: import parsedatetime.parsedatetime_consts as pdt +except ImportError: import parsedatetime as pdt + +parser = argparse.ArgumentParser() +parser.add_argument('-i', default='today') +parser.add_argument('-f', default=None) +args = parser.parse_args() +print "args: " + str(args) +date_str = args.i +end_flag = args.f + +# Set up date parser +consts = pdt.Constants(usePyICU=False) +consts.DOWParseStyle = -1 # "Monday" will be either today or the last Monday +dateparse = pdt.Calendar(consts) + +if not date_str: + print "Nothing supplied" + # return None +elif isinstance(date_str, datetime): + print date_str + # return date_str + +try: + date = dateutil.parser.parse(date_str) + flag = 1 if date.hour == 0 and date.minute == 0 else 2 + date = date.timetuple() +except: + date, flag = dateparse.parse(date_str) + +if not flag: # Oops, unparsable. + try: # Try and parse this as a single year + year = int(date_str) + print datetime(year, 1, 1) + # return datetime(year, 1, 1) + except ValueError: + print "return None" + # return None + except TypeError: + print "return None" + # return None + +if flag is 1: # Date found, but no time. Use the default time. + if end_flag == "from": + date = datetime(*date[:3], hour=0, minute=0) + elif end_flag == "to": + date = datetime(*date[:3], hour=23, minute=59, second=59) + else: + # Use the default time. + date = datetime(*date[:3], hour=9, minute=1) +else: + date = datetime(*date[:6]) + +# Ugly heuristic: if the date is more than 4 weeks in the future, we got the year wrong. +# 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: + date = date.replace(date.year - 1) + +print date +# return date \ No newline at end of file From 69dafdc39b35ac9155e60a99e8a1ab34f5158e55 Mon Sep 17 00:00:00 2001 From: William Minchin Date: Fri, 7 Feb 2014 10:35:35 -0700 Subject: [PATCH 02/12] Remove parse-date-test.py --- .gitignore | 3 +++ parse-date-test.py | 67 ---------------------------------------------- 2 files changed, 3 insertions(+), 67 deletions(-) delete mode 100644 parse-date-test.py diff --git a/.gitignore b/.gitignore index 1a8fd1b8..d62c96cd 100644 --- a/.gitignore +++ b/.gitignore @@ -42,3 +42,6 @@ obj # virtaulenv env/ env*/ + +#random extras +extras/ diff --git a/parse-date-test.py b/parse-date-test.py deleted file mode 100644 index 5ff9e42e..00000000 --- a/parse-date-test.py +++ /dev/null @@ -1,67 +0,0 @@ -"""Parses a string containing a fuzzy date and returns a datetime.datetime object""" - -from datetime import datetime -import dateutil -import argparse -try: import parsedatetime.parsedatetime_consts as pdt -except ImportError: import parsedatetime as pdt - -parser = argparse.ArgumentParser() -parser.add_argument('-i', default='today') -parser.add_argument('-f', default=None) -args = parser.parse_args() -print "args: " + str(args) -date_str = args.i -end_flag = args.f - -# Set up date parser -consts = pdt.Constants(usePyICU=False) -consts.DOWParseStyle = -1 # "Monday" will be either today or the last Monday -dateparse = pdt.Calendar(consts) - -if not date_str: - print "Nothing supplied" - # return None -elif isinstance(date_str, datetime): - print date_str - # return date_str - -try: - date = dateutil.parser.parse(date_str) - flag = 1 if date.hour == 0 and date.minute == 0 else 2 - date = date.timetuple() -except: - date, flag = dateparse.parse(date_str) - -if not flag: # Oops, unparsable. - try: # Try and parse this as a single year - year = int(date_str) - print datetime(year, 1, 1) - # return datetime(year, 1, 1) - except ValueError: - print "return None" - # return None - except TypeError: - print "return None" - # return None - -if flag is 1: # Date found, but no time. Use the default time. - if end_flag == "from": - date = datetime(*date[:3], hour=0, minute=0) - elif end_flag == "to": - date = datetime(*date[:3], hour=23, minute=59, second=59) - else: - # Use the default time. - date = datetime(*date[:3], hour=9, minute=1) -else: - date = datetime(*date[:6]) - -# Ugly heuristic: if the date is more than 4 weeks in the future, we got the year wrong. -# 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: - date = date.replace(date.year - 1) - -print date -# return date \ No newline at end of file From 4df237589bb0ed9f5ca1a095f0c83a07ae34f651 Mon Sep 17 00:00:00 2001 From: William Minchin Date: Sat, 8 Feb 2014 10:54:02 -0700 Subject: [PATCH 03/12] Add date tests but don't have Travis-CI run them yet --- .travis.yml | 2 +- features/dates.feature | 156 +++++++++++++++++++++++++++++++++++++++++ jrnl/Journal.py | 6 +- 3 files changed, 161 insertions(+), 3 deletions(-) create mode 100644 features/dates.feature diff --git a/.travis.yml b/.travis.yml index 12928624..62a5ec9f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,7 +10,7 @@ install: # command to run tests script: - python --version - - behave + - behave --tages=-wip matrix: allow_failures: # python 3 support for travis is shaky.... - python: 3.3 diff --git a/features/dates.feature b/features/dates.feature new file mode 100644 index 00000000..a95fdcc1 --- /dev/null +++ b/features/dates.feature @@ -0,0 +1,156 @@ + +@dates @wip +Feature: Processing of dates and times + + Scenario Outline: Test all sorts of dates + Given we use the config "basic.json" + When we run "jrnl" and enter " I saw Elvis. " + Then we should get no error + and the journal should contain " I saw Elvis. " + + Examples: no date + | date in | date out | entry no | + | | | 1 | + + Examples: strings + | date in | date out | entry no | + | today | | 2 | + | tomorrow | | 3 | + | yesterday | | 4 | + + Examples: strings with times + | date in | date out | entry no | + | today 2pm | | 5 | + | today at 3pm | | 6 | + | today 8am | | 7 | + | today 16:27 | | 8 | + | today 5:18 | | 9 | + | today 6:47pm | | 10 | + + Examples: days of the week + | date in | date out | entry no | + | monday | | 11 | + | tuesday | | 12 | + | wednesday | | 13 | + | thrusday | | 14 | + | friday | | 15 | + | saturday | | 16 | + | sunday | | 17 | + + Examples: days of the week + | date in | date out | entry no | + | mon | | 18 | + | tues | | 19 | + | wed | | 20 | + | thrus | | 21 | + | fri | | 22 | + | sat | | 23 | + | sun | | 24 | + | tue | | 25 | + | thr | | 26 | + + Examples: days of the week with a time + | date in | date out | entry no | + | mon at 5am | | 27 | + + Examples: Qualified days of the week + | date in | date out | entry no | + | last monday | | 28 | + | next monday | | 29 | + + Examples: Just times + | date in | date out | entry no | + | at 8pm | | 30 | + | noon | | 31 | + | midnight | | 32 | + + Examples: short months + | date in | date out | entry no | + | jan | | 33 | + | feb | | 34 | + | mar | | 35 | + | apr | | 36 | + | may | | 37 | + | jun | | 38 | + | jul | | 39 | + | aug | | 40 | + | sep | | 41 | + | oct | | 42 | + | nov | | 43 | + | dec | | 44 | + | sept | | 45 | + + Examples: long months + | date in | date out | entry no | + | january | | 46 | + | february | | 47 | + | march | | 48 | + | april | | 49 | + | june | | 50 | + | july | | 51 | + | august | | 52 | + | september | | 53 | + | october | | 54 | + | november | | 55 | + | december | | 56 | + + Examples: month + day (no year) + | date in | date out | entry no | + | 7 apr | | 57 | + | apr 8 | | 58 | + | 9 march | | 59 | + | march 10 | | 60 | + + Examples: year + | date in | date out | entry no | + | 1998 | 1998-01-01 9:00 | 61 | + | 2013 | 2013-01-01 9:00 | 62 | + | 2014 | 2014-01-01 9:00 | 63 | + | 2015 | 2015-01-01 9:00 | 64 | + | 2051 | 2051-01-01 9:00 | 65 | + + Examples: year + month + | date in | date out | entry no | + | jun 2013 | 2013-06-01 9:00 | 66 | + | 2013 jul | 2013-07-01 9:00 | 67 | + | august 2013 | 2013-08-01 9:00 | 68 | + | 2013 september | 2013-09-01 9:00 | 69 | + + Examples: 'YYYY-MM-DD' dates (with and without times) + | date in | date out | entry no | + | 2013-06-07 | 2013-06-07 9:00 | 70 | + | 2013-06-07 8:11 | 2013-06-07 8:11 | 71 | + | 2013-06-07 08:12 | 2013-06-07 8:12 | 72 | + | 2013-06-07 20:13 | 2013-06-07 20:13 | 73 | + + Examples: 'YYYY-MMM-DD' dates (with and without times) + | date in | date out | entry no | + | 2013-may-07 | 2013-05-07 9:00 | 74 | + | 2013-may-07 8:11 | 2013-05-07 8:11 | 75 | + | 2013-may-07 08:12 | 2013-05-07 8:12 | 76 | + | 2013-may-07 20:13 | 2013-05-07 20:13 | 77 | + + Examples: Full dates, with written montsh + | date in | date out | entry no | + | Feb 5, 2014 | 2014-02-05 9:00 | 78 | + | Feb 06, 2014 | 2014-02-06 9:00 | 79 | + | Feb. 7, 2014 | 2014-02-07 9:00 | 80 | + | Feb. 08, 2014 | 2014-02-08 9:00 | 81 | + | 9 Feb 2014 | 2014-02-09 9:00 | 82 | + | 01 Feb 2014 | 2014-02-01 9:00 | 83 | + | 2 Feb. 2014 | 2014-02-02 9:00 | 84 | + | 03 Feb. 2014 | 2014-02-03 9:00 | 85 | + + Examples: 'YYYY/MM/DD' dates (with and without times) + | date in | date out | entry no | + | 2013/06/07 | 2013-06-07 9:00 | 86 | + | 2013/06/07 8:11 | 2013-06-07 8:11 | 87 | + | 2013/06/07 08:12 | 2013-06-07 8:12 | 88 | + | 2013/06/07 20:13 | 2013-06-07 20:13 | 89 | + + Examples: 'DD/MM/YYYY' dates (with and without times) + | date in | date out | entry no | + | 13/06/2007 | 2007-06-13 9:00 | 90 | + | 13/06/2007 8:11 | 2007-06-13 8:11 | 91 | + | 13/06/2007 08:12 | 2007-06-13 8:12 | 92 | + | 13/06/2007 20:13 | 2007-06-13 20:13 | 93 | diff --git a/jrnl/Journal.py b/jrnl/Journal.py index a5a345b8..5050231e 100644 --- a/jrnl/Journal.py +++ b/jrnl/Journal.py @@ -6,8 +6,10 @@ from . import Entry from . import util import codecs import os -try: import parsedatetime.parsedatetime_consts as pdt -except ImportError: import parsedatetime as pdt +try: + import parsedatetime.parsedatetime_consts as pdt +except ImportError: + import parsedatetime as pdt import re from datetime import datetime import dateutil From 65aae7e0bedc5fcdf86038c43218ad2af75d891d Mon Sep 17 00:00:00 2001 From: William Minchin Date: Sat, 8 Feb 2014 13:08:38 -0700 Subject: [PATCH 04/12] Expand date tests of the 93 tests added, it passes 47 --- .travis.yml | 2 +- features/data/configs/empty.json | 14 ++ features/data/journals/empty.journal | 0 features/dates.feature | 210 +++++++++++---------------- features/dates2.feature | 63 ++++++++ features/environment.py | 22 ++- 6 files changed, 179 insertions(+), 132 deletions(-) create mode 100644 features/data/configs/empty.json create mode 100644 features/data/journals/empty.journal create mode 100644 features/dates2.feature diff --git a/.travis.yml b/.travis.yml index 62a5ec9f..6fb6040c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,7 +10,7 @@ install: # command to run tests script: - python --version - - behave --tages=-wip + - "behave --tages='-wip'" matrix: allow_failures: # python 3 support for travis is shaky.... - python: 3.3 diff --git a/features/data/configs/empty.json b/features/data/configs/empty.json new file mode 100644 index 00000000..3cb40b1a --- /dev/null +++ b/features/data/configs/empty.json @@ -0,0 +1,14 @@ +{ + "default_hour": 9, + "timeformat": "%Y-%m-%d %H:%M", + "linewrap": 80, + "encrypt": false, + "editor": "", + "default_minute": 0, + "highlight": true, + "password": "", + "journals": { + "default": "features/journals/empty.journal" + }, + "tagsymbols": "@" +} \ No newline at end of file diff --git a/features/data/journals/empty.journal b/features/data/journals/empty.journal new file mode 100644 index 00000000..e69de29b diff --git a/features/dates.feature b/features/dates.feature index a95fdcc1..1a337060 100644 --- a/features/dates.feature +++ b/features/dates.feature @@ -1,156 +1,110 @@ -@dates @wip -Feature: Processing of dates and times +@dates1 @dates @wip +Feature: Processing of (relative) dates and times + # all these test are 'brittle', in that they depend on the day it is run + # these results assume the test is run on Feb 8, 2014 - Scenario Outline: Test all sorts of dates + Scenario Outline: no date Given we use the config "basic.json" - When we run "jrnl" and enter " I saw Elvis. " - Then we should get no error - and the journal should contain " I saw Elvis. " + When we run "jrnl I saw Elvis . He's alive!" + Then we should get no error + Then the journal should contain " I saw Elvis " Examples: no date - | date in | date out | entry no | - | | | 1 | + | date in | date out | entry no | + | | 2014-02-08 09:00 | 1 | + + Scenario Outline: Test all sorts of (non-fixed) dates + Given we use the config "empty.json" + When we run "jrnl : I saw Elvis ." + Then we should get no error + Then the journal should contain " I saw Elvis " Examples: strings - | date in | date out | entry no | - | today | | 2 | - | tomorrow | | 3 | - | yesterday | | 4 | + | date in | date out | entry no | + | today | 2014-02-08 09:00 | 2 | + | tomorrow | 2014-02-09 09:00 | 3 | + | yesterday | 2014-02-07 09:00 | 4 | Examples: strings with times - | date in | date out | entry no | - | today 2pm | | 5 | - | today at 3pm | | 6 | - | today 8am | | 7 | - | today 16:27 | | 8 | - | today 5:18 | | 9 | - | today 6:47pm | | 10 | + | date in | date out | entry no | + | today 2pm | 2014-02-08 14:00 | 5 | + | today at 3pm | 2014-02-08 15:00 | 6 | + | today 8am | 2014-02-08 08:00 | 7 | + | today 16:27 | 2014-02-08 16:27 | 8 | + | today 5:18 | 2014-02-08 05:18 | 9 | + | today 6:47pm | 2014-02-08 18:47 | 10 | Examples: days of the week - | date in | date out | entry no | - | monday | | 11 | - | tuesday | | 12 | - | wednesday | | 13 | - | thrusday | | 14 | - | friday | | 15 | - | saturday | | 16 | - | sunday | | 17 | + | date in | date out | entry no | + | monday | 2014-02-10 09:00 | 11 | + | tuesday | 2014-02-11 09:00 | 12 | + | wednesday | 2014-02-12 09:00 | 13 | + | thursday | 2014-02-13 09:00 | 14 | + | friday | 2014-02-14 09:00 | 15 | + | saturday | 2014-02-08 09:00 | 16 | + | sunday | 2014-02-09 09:00 | 17 | Examples: days of the week - | date in | date out | entry no | - | mon | | 18 | - | tues | | 19 | - | wed | | 20 | - | thrus | | 21 | - | fri | | 22 | - | sat | | 23 | - | sun | | 24 | - | tue | | 25 | - | thr | | 26 | + | date in | date out | entry no | + | mon | 2014-02-10 09:00 | 18 | + | tues | 2014-02-11 09:00 | 19 | + | wed | 2014-02-12 09:00 | 20 | + | thurs | 2014-02-13 09:00 | 21 | + | fri | 2014-02-14 09:00 | 22 | + | sat | 2014-02-08 09:00 | 23 | + | sun | 2014-02-09 09:00 | 24 | + | tue | 2014-02-11 09:00 | 25 | + | thu | 2014-02-13 09:00 | 26 | Examples: days of the week with a time - | date in | date out | entry no | - | mon at 5am | | 27 | + | date in | date out | entry no | + | mon at 5am | 2014-02-10 05:00 | 27 | Examples: Qualified days of the week | date in | date out | entry no | - | last monday | | 28 | - | next monday | | 29 | + | last monday |2014-02-03 09:00 | 28 | + | next monday |2014-02-10 09:00 | 29 | Examples: Just times | date in | date out | entry no | - | at 8pm | | 30 | - | noon | | 31 | - | midnight | | 32 | + | at 8pm |2014-02-10 20:00 | 30 | + | noon |2014-02-10 12:00 | 31 | + | midnight |2014-02-10 00:00 | 32 | Examples: short months - | date in | date out | entry no | - | jan | | 33 | - | feb | | 34 | - | mar | | 35 | - | apr | | 36 | - | may | | 37 | - | jun | | 38 | - | jul | | 39 | - | aug | | 40 | - | sep | | 41 | - | oct | | 42 | - | nov | | 43 | - | dec | | 44 | - | sept | | 45 | + | date in | date out | entry no | + | jan | 2015-01-01 09:00 | 33 | + | feb | 2014-02-01 09:00 | 34 | + | mar | 2014-03-01 09:00 | 35 | + | apr | 2014-04-01 09:00 | 36 | + | may | 2014-05-01 09:00 | 37 | + | jun | 2014-06-01 09:00 | 38 | + | jul | 2014-07-01 09:00 | 39 | + | aug | 2014-08-01 09:00 | 40 | + | sep | 2014-09-01 09:00 | 41 | + | oct | 2014-10-01 09:00 | 42 | + | nov | 2014-11-01 09:00 | 43 | + | dec | 2014-12-01 09:00 | 44 | + | sept | 2014-09-01 09:00 | 45 | Examples: long months - | date in | date out | entry no | - | january | | 46 | - | february | | 47 | - | march | | 48 | - | april | | 49 | - | june | | 50 | - | july | | 51 | - | august | | 52 | - | september | | 53 | - | october | | 54 | - | november | | 55 | - | december | | 56 | + | date in | date out | entry no | + | january | 2015-01-01 09:00 | 46 | + | february | 2014-02-01 09:00 | 47 | + | march | 2014-03-01 09:00 | 48 | + | april | 2014-04-01 09:00 | 49 | + | june | 2014-06-01 09:00 | 50 | + | july | 2014-07-01 09:00 | 51 | + | august | 2014-08-01 09:00 | 52 | + | september | 2014-09-01 09:00 | 53 | + | october | 2014-10-01 09:00 | 54 | + | november | 2014-11-01 09:00 | 55 | + | december | 2014-12-01 09:00 | 56 | Examples: month + day (no year) - | date in | date out | entry no | - | 7 apr | | 57 | - | apr 8 | | 58 | - | 9 march | | 59 | - | march 10 | | 60 | - - Examples: year | date in | date out | entry no | - | 1998 | 1998-01-01 9:00 | 61 | - | 2013 | 2013-01-01 9:00 | 62 | - | 2014 | 2014-01-01 9:00 | 63 | - | 2015 | 2015-01-01 9:00 | 64 | - | 2051 | 2051-01-01 9:00 | 65 | - - Examples: year + month - | date in | date out | entry no | - | jun 2013 | 2013-06-01 9:00 | 66 | - | 2013 jul | 2013-07-01 9:00 | 67 | - | august 2013 | 2013-08-01 9:00 | 68 | - | 2013 september | 2013-09-01 9:00 | 69 | - - Examples: 'YYYY-MM-DD' dates (with and without times) - | date in | date out | entry no | - | 2013-06-07 | 2013-06-07 9:00 | 70 | - | 2013-06-07 8:11 | 2013-06-07 8:11 | 71 | - | 2013-06-07 08:12 | 2013-06-07 8:12 | 72 | - | 2013-06-07 20:13 | 2013-06-07 20:13 | 73 | - - Examples: 'YYYY-MMM-DD' dates (with and without times) - | date in | date out | entry no | - | 2013-may-07 | 2013-05-07 9:00 | 74 | - | 2013-may-07 8:11 | 2013-05-07 8:11 | 75 | - | 2013-may-07 08:12 | 2013-05-07 8:12 | 76 | - | 2013-may-07 20:13 | 2013-05-07 20:13 | 77 | - - Examples: Full dates, with written montsh - | date in | date out | entry no | - | Feb 5, 2014 | 2014-02-05 9:00 | 78 | - | Feb 06, 2014 | 2014-02-06 9:00 | 79 | - | Feb. 7, 2014 | 2014-02-07 9:00 | 80 | - | Feb. 08, 2014 | 2014-02-08 9:00 | 81 | - | 9 Feb 2014 | 2014-02-09 9:00 | 82 | - | 01 Feb 2014 | 2014-02-01 9:00 | 83 | - | 2 Feb. 2014 | 2014-02-02 9:00 | 84 | - | 03 Feb. 2014 | 2014-02-03 9:00 | 85 | - - Examples: 'YYYY/MM/DD' dates (with and without times) - | date in | date out | entry no | - | 2013/06/07 | 2013-06-07 9:00 | 86 | - | 2013/06/07 8:11 | 2013-06-07 8:11 | 87 | - | 2013/06/07 08:12 | 2013-06-07 8:12 | 88 | - | 2013/06/07 20:13 | 2013-06-07 20:13 | 89 | - - Examples: 'DD/MM/YYYY' dates (with and without times) - | date in | date out | entry no | - | 13/06/2007 | 2007-06-13 9:00 | 90 | - | 13/06/2007 8:11 | 2007-06-13 8:11 | 91 | - | 13/06/2007 08:12 | 2007-06-13 8:12 | 92 | - | 13/06/2007 20:13 | 2007-06-13 20:13 | 93 | + | 7 apr | 2014-04-07 09:00 | 57 | + | apr 8 | 2014-04-08 09:00 | 58 | + | 9 march | 2014-03-09 09:00 | 59 | + | march 10 | 2014-03-10 09:00 | 60 | diff --git a/features/dates2.feature b/features/dates2.feature new file mode 100644 index 00000000..c6ee24aa --- /dev/null +++ b/features/dates2.feature @@ -0,0 +1,63 @@ + +@dates2 @dates @wip +Feature: Processing of (fixed) dates and times + + Scenario Outline: Test all sorts of (fixed) dates + Given we use the config "empty.json" + When we run "jrnl : I saw Elvis . He's Alive!" + Then we should get no error + Then the journal should contain " I saw Elvis " + + Examples: year + | date in | date out | entry no | + | 1998 | 1998-01-01 09:00 | 61 | + | 2013 | 2013-01-01 09:00 | 62 | + | 2014 | 2014-01-01 09:00 | 63 | + | 2015 | 2015-01-01 09:00 | 64 | + | 2051 | 2051-01-01 09:00 | 65 | + + Examples: year + month + | date in | date out | entry no | + | jun 2013 | 2013-06-01 09:00 | 66 | + | 2013 jul | 2013-07-01 09:00 | 67 | + | august 2013 | 2013-08-01 09:00 | 68 | + | 2013 september | 2013-09-01 09:00 | 69 | + + Examples: 'YYYY-MM-DD' dates (with and without times) + | date in | date out | entry no | + | 2013-06-07 | 2013-06-07 09:00 | 70 | + | 2013-06-07 8:11 | 2013-06-07 08:11 | 71 | + | 2013-06-07 08:12 | 2013-06-07 08:12 | 72 | + | 2013-06-07 20:13 | 2013-06-07 20:13 | 73 | + + Examples: 'YYYY-MMM-DD' dates (with and without times) + | date in | date out | entry no | + | 2013-may-07 | 2013-05-07 09:00 | 74 | + | 2013-may-07 8:11 | 2013-05-07 08:11 | 75 | + | 2013-may-07 08:12 | 2013-05-07 08:12 | 76 | + | 2013-may-07 20:13 | 2013-05-07 20:13 | 77 | + + Examples: Full dates, with written montsh + | date in | date out | entry no | + | Feb 5, 2014 | 2014-02-05 09:00 | 78 | + | Feb 06, 2014 | 2014-02-06 09:00 | 79 | + | Feb. 7, 2014 | 2014-02-07 09:00 | 80 | + | Feb. 08, 2014 | 2014-02-08 09:00 | 81 | + | 9 Feb 2014 | 2014-02-09 09:00 | 82 | + | 01 Feb 2014 | 2014-02-01 09:00 | 83 | + | 2 Feb. 2014 | 2014-02-02 09:00 | 84 | + | 03 Feb. 2014 | 2014-02-03 09:00 | 85 | + + Examples: 'YYYY/MM/DD' dates (with and without times) + | date in | date out | entry no | + | 2013/06/07 | 2013-06-07 09:00 | 86 | + | 2013/06/07 8:11 | 2013-06-07 08:11 | 87 | + | 2013/06/07 08:12 | 2013-06-07 08:12 | 88 | + | 2013/06/07 20:13 | 2013-06-07 20:13 | 89 | + + Examples: 'DD/MM/YYYY' dates (with and without times) + | date in | date out | entry no | + | 13/06/2007 | 2007-06-13 09:00 | 90 | + | 13/06/2007 8:11 | 2007-06-13 08:11 | 91 | + | 13/06/2007 08:12 | 2007-06-13 08:12 | 92 | + | 13/06/2007 20:13 | 2007-06-13 20:13 | 93 | diff --git a/features/environment.py b/features/environment.py index 6f9ac5df..fc5793ee 100644 --- a/features/environment.py +++ b/features/environment.py @@ -1,6 +1,7 @@ from behave import * import shutil import os +import time import jrnl try: from io import StringIO @@ -17,14 +18,24 @@ def before_scenario(context, scenario): for folder in ("configs", "journals"): working_dir = os.path.join("features", folder) if os.path.exists(working_dir): - shutil.rmtree(working_dir) + try: + shutil.rmtree(working_dir) + except: + # give it a second go at it... + time.sleep(0.5) + shutil.rmtree(working_dir) for folder in ("configs", "journals"): original = os.path.join("features", "data", folder) working_dir = os.path.join("features", folder) if not os.path.exists(working_dir): - os.mkdir(working_dir) + try: + os.mkdir(working_dir) + except: + # give it a second go at it... + time.sleep(0.5) + os.mkdir(working_dir) for filename in os.listdir(original): source = os.path.join(original, filename) if os.path.isdir(source): @@ -39,4 +50,9 @@ def after_scenario(context, scenario): for folder in ("configs", "journals"): working_dir = os.path.join("features", folder) if os.path.exists(working_dir): - shutil.rmtree(working_dir) + try: + shutil.rmtree(working_dir) + except: + # give it a second go at it... + time.sleep(0.5) + shutil.rmtree(working_dir) From 5226d82c54434811c141d95b0cb4527246b43d77 Mon Sep 17 00:00:00 2001 From: William Minchin Date: Sat, 8 Feb 2014 13:14:01 -0700 Subject: [PATCH 05/12] Skip `Work in Progress` tests --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 6fb6040c..f4684577 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,7 +10,7 @@ install: # command to run tests script: - python --version - - "behave --tages='-wip'" + - "behave --tages ~wip" matrix: allow_failures: # python 3 support for travis is shaky.... - python: 3.3 From 8388198eae8930cc762aad290d84cf29c9a1900b Mon Sep 17 00:00:00 2001 From: William Minchin Date: Sat, 8 Feb 2014 14:15:14 -0700 Subject: [PATCH 06/12] Note how `jrnl` deals with dates without a year --- features/dates.feature | 24 ++++++++++++++---------- features/dates2.feature | 1 + 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/features/dates.feature b/features/dates.feature index 1a337060..cb4db436 100644 --- a/features/dates.feature +++ b/features/dates.feature @@ -5,14 +5,14 @@ Feature: Processing of (relative) dates and times # these results assume the test is run on Feb 8, 2014 Scenario Outline: no date - Given we use the config "basic.json" + Given we use the config "empty.json" When we run "jrnl I saw Elvis . He's alive!" Then we should get no error Then the journal should contain " I saw Elvis " Examples: no date | date in | date out | entry no | - | | 2014-02-08 09:00 | 1 | + | | 2014-02-08 13:24 | 1 | Scenario Outline: Test all sorts of (non-fixed) dates Given we use the config "empty.json" @@ -67,10 +67,11 @@ Feature: Processing of (relative) dates and times | next monday |2014-02-10 09:00 | 29 | Examples: Just times - | date in | date out | entry no | - | at 8pm |2014-02-10 20:00 | 30 | - | noon |2014-02-10 12:00 | 31 | - | midnight |2014-02-10 00:00 | 32 | + | date in | date out | entry no | + | at 8pm |2014-02-08 20:00 | 30 | + | noon |2014-02-08 12:00 | 31 | + | midnight |2014-02-08 00:00 | 32 | + | 2 o'clock |2014-02-08 02:00 | 32 bis | Examples: short months | date in | date out | entry no | @@ -103,8 +104,11 @@ Feature: Processing of (relative) dates and times | december | 2014-12-01 09:00 | 56 | Examples: month + day (no year) + # unless within 28 days, assumed to be the last occurance + # if in the next 28 days, assumed to be then | date in | date out | entry no | - | 7 apr | 2014-04-07 09:00 | 57 | - | apr 8 | 2014-04-08 09:00 | 58 | - | 9 march | 2014-03-09 09:00 | 59 | - | march 10 | 2014-03-10 09:00 | 60 | + | 7 apr | 2013-04-07 09:00 | 57 | + | apr 8 | 2013-04-08 09:00 | 58 | + | 9 march | 2013-03-09 09:00 | 59 | + | march 10 | 2013-03-10 09:00 | 60 | + | march 7 | 2014-03-07 09:00 | 60 bis | diff --git a/features/dates2.feature b/features/dates2.feature index c6ee24aa..59ca8d4c 100644 --- a/features/dates2.feature +++ b/features/dates2.feature @@ -14,6 +14,7 @@ Feature: Processing of (fixed) dates and times | 2013 | 2013-01-01 09:00 | 62 | | 2014 | 2014-01-01 09:00 | 63 | | 2015 | 2015-01-01 09:00 | 64 | + | 2050 | 2050-01-01 09:00 | 64 bis | | 2051 | 2051-01-01 09:00 | 65 | Examples: year + month From da28dc924986f0724c0bf75de81b596905f62fd7 Mon Sep 17 00:00:00 2001 From: William Minchin Date: Sat, 8 Feb 2014 14:18:36 -0700 Subject: [PATCH 07/12] speling --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f4684577..8118f366 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,7 +10,7 @@ install: # command to run tests script: - python --version - - "behave --tages ~wip" + - "behave --tags ~wip" matrix: allow_failures: # python 3 support for travis is shaky.... - python: 3.3 From aede53a9f470ba021329439396ddff8f0db0b162 Mon Sep 17 00:00:00 2001 From: William Minchin Date: Sat, 8 Feb 2014 14:40:49 -0700 Subject: [PATCH 08/12] Fix dealing with plain years `-from` and `-to` flags also work --- jrnl/Journal.py | 64 ++++++++++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 27 deletions(-) diff --git a/jrnl/Journal.py b/jrnl/Journal.py index 5050231e..06cacff5 100644 --- a/jrnl/Journal.py +++ b/jrnl/Journal.py @@ -244,39 +244,49 @@ class Journal(object): elif isinstance(date_str, datetime): return date_str - try: - date = dateutil.parser.parse(date_str) - flag = 1 if date.hour == 0 and date.minute == 0 else 2 - date = date.timetuple() - except: - date, flag = self.dateparse.parse(date_str) - - if not flag: # Oops, unparsable. - try: # Try and parse this as a single year - year = int(date_str) - return datetime(year, 1, 1) - except ValueError: - return None - except TypeError: - return None - - if flag is 1: # Date found, but no time. + if re.match(r'^\d{4}$', date_str): + # i.e. if we're just given a year if end_flag == "from": - date = datetime(*date[:3], hour=0, minute=0) + date = datetime(year=int(date_str), month=1, day=1, hour=0, minute=0) elif end_flag == "to": - date = datetime(*date[:3], hour=23, minute=59, second=59) + date = datetime(year=int(date_str), month=12, day=31, hour=23, minute=59, second=59) else: # Use the default time. - date = datetime(*date[:3], hour=self.config['default_hour'], minute=self.config['default_minute']) + date = datetime(year=int(date_str), month=1, day=1, hour=self.config['default_hour'], minute=self.config['default_minute']) else: - date = datetime(*date[:6]) + try: + date = dateutil.parser.parse(date_str) + flag = 1 if date.hour == 0 and date.minute == 0 else 2 + date = date.timetuple() + except: + date, flag = self.dateparse.parse(date_str) - # Ugly heuristic: if the date is more than 4 weeks in the future, we got the year wrong. - # 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: - date = date.replace(date.year - 1) + if not flag: # Oops, unparsable. + try: # Try and parse this as a single year + year = int(date_str) + return datetime(year, 1, 1) + except ValueError: + return None + except TypeError: + return None + + if flag is 1: # Date found, but no time. + if end_flag == "from": + date = datetime(*date[:3], hour=0, minute=0) + elif end_flag == "to": + date = datetime(*date[:3], hour=23, minute=59, second=59) + else: + # Use the default time. + date = datetime(*date[:3], hour=self.config['default_hour'], minute=self.config['default_minute']) + else: + date = datetime(*date[:6]) + + # Ugly heuristic: if the date is more than 4 weeks in the future, we got the year wrong. + # 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: + date = date.replace(date.year - 1) return date From b0a29736d7db42cb1d2294968e5fb80e82f16f6d Mon Sep 17 00:00:00 2001 From: William Minchin Date: Sat, 8 Feb 2014 15:29:54 -0700 Subject: [PATCH 09/12] String replacement to deal with more dates deals with `tues`, `thurs`, `sept`, and ` o'clock` --- jrnl/Journal.py | 5 +++++ jrnl/util.py | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/jrnl/Journal.py b/jrnl/Journal.py index 06cacff5..cbf754a2 100644 --- a/jrnl/Journal.py +++ b/jrnl/Journal.py @@ -254,6 +254,11 @@ class Journal(object): # Use the default time. date = datetime(year=int(date_str), month=1, day=1, hour=self.config['default_hour'], minute=self.config['default_minute']) else: + replacements = (u"september", u"sep"), (u"sept", u"sep"), (u"tuesday", u"tue"), \ + (u"tues", u"tue"), (u"thursday", u"thu"), (u"thurs", u"thu"), \ + (u" o'clock", u":00") + date_str = util.multiple_replace(date_str, *replacements) + try: date = dateutil.parser.parse(date_str) flag = 1 if date.hour == 0 and date.minute == 0 else 2 diff --git a/jrnl/util.py b/jrnl/util.py index 4b252cbd..13f92af4 100644 --- a/jrnl/util.py +++ b/jrnl/util.py @@ -141,3 +141,19 @@ def slugify(string): slug = re.sub(r'[-\s]+', '-', no_punctuation) return u(slug) +# Use the following two functions to do multiple replacements in one pass +# from http://stackoverflow.com/questions/6116978/python-replace-multiple-strings +# +# Useage: +# >>> replacements = (u"café", u"tea"), (u"tea", u"café"), (u"like", u"love") +# >>> print multiple_replace(u"Do you like café? No, I prefer tea.", *replacements) +# output: Do you love tea? No, I prefer café. + +def multiple_replacer(*key_values): + replace_dict = dict(key_values) + replacement_function = lambda match: replace_dict[match.group(0)] + pattern = re.compile("|".join([re.escape(k) for k, v in key_values]), re.M | re.I) + return lambda string: pattern.sub(replacement_function, string) + +def multiple_replace(string, *key_values): + return multiple_replacer(*key_values)(string) From 96525759286aad24c4f3f75723cd282dbac23679 Mon Sep 17 00:00:00 2001 From: William Minchin Date: Mon, 10 Feb 2014 13:24:42 -0700 Subject: [PATCH 10/12] deal with months allow `-to` and `-from` to work on bare months; also if just a month is given for an entry, assume the default time on the 1st of the month. --- features/dates.feature | 40 ++++++++-------- features/dates2.feature | 2 +- jrnl/Journal.py | 101 +++++++++++++++++++++++++++++----------- 3 files changed, 96 insertions(+), 47 deletions(-) diff --git a/features/dates.feature b/features/dates.feature index cb4db436..ba86b224 100644 --- a/features/dates.feature +++ b/features/dates.feature @@ -75,33 +75,33 @@ Feature: Processing of (relative) dates and times Examples: short months | date in | date out | entry no | - | jan | 2015-01-01 09:00 | 33 | + | jan | 2014-01-01 09:00 | 33 | | feb | 2014-02-01 09:00 | 34 | | mar | 2014-03-01 09:00 | 35 | - | apr | 2014-04-01 09:00 | 36 | - | may | 2014-05-01 09:00 | 37 | - | jun | 2014-06-01 09:00 | 38 | - | jul | 2014-07-01 09:00 | 39 | - | aug | 2014-08-01 09:00 | 40 | - | sep | 2014-09-01 09:00 | 41 | - | oct | 2014-10-01 09:00 | 42 | - | nov | 2014-11-01 09:00 | 43 | - | dec | 2014-12-01 09:00 | 44 | - | sept | 2014-09-01 09:00 | 45 | + | apr | 2013-04-01 09:00 | 36 | + | may | 2013-05-01 09:00 | 37 | + | jun | 2013-06-01 09:00 | 38 | + | jul | 2013-07-01 09:00 | 39 | + | aug | 2013-08-01 09:00 | 40 | + | sep | 2013-09-01 09:00 | 41 | + | oct | 2013-10-01 09:00 | 42 | + | nov | 2013-11-01 09:00 | 43 | + | dec | 2013-12-01 09:00 | 44 | + | sept | 2013-09-01 09:00 | 45 | Examples: long months | date in | date out | entry no | - | january | 2015-01-01 09:00 | 46 | + | january | 2014-01-01 09:00 | 46 | | february | 2014-02-01 09:00 | 47 | | march | 2014-03-01 09:00 | 48 | - | april | 2014-04-01 09:00 | 49 | - | june | 2014-06-01 09:00 | 50 | - | july | 2014-07-01 09:00 | 51 | - | august | 2014-08-01 09:00 | 52 | - | september | 2014-09-01 09:00 | 53 | - | october | 2014-10-01 09:00 | 54 | - | november | 2014-11-01 09:00 | 55 | - | december | 2014-12-01 09:00 | 56 | + | april | 2013-04-01 09:00 | 49 | + | june | 2013-06-01 09:00 | 50 | + | july | 2013-07-01 09:00 | 51 | + | august | 2013-08-01 09:00 | 52 | + | september | 2013-09-01 09:00 | 53 | + | october | 2013-10-01 09:00 | 54 | + | november | 2013-11-01 09:00 | 55 | + | december | 2013-12-01 09:00 | 56 | Examples: month + day (no year) # unless within 28 days, assumed to be the last occurance diff --git a/features/dates2.feature b/features/dates2.feature index 59ca8d4c..1b51e55b 100644 --- a/features/dates2.feature +++ b/features/dates2.feature @@ -1,5 +1,5 @@ -@dates2 @dates @wip +@dates2 @dates Feature: Processing of (fixed) dates and times Scenario Outline: Test all sorts of (fixed) dates diff --git a/jrnl/Journal.py b/jrnl/Journal.py index cbf754a2..4fc62d02 100644 --- a/jrnl/Journal.py +++ b/jrnl/Journal.py @@ -11,6 +11,7 @@ try: except ImportError: import parsedatetime as pdt import re +from datetime import timedelta from datetime import datetime import dateutil import time @@ -254,44 +255,92 @@ class Journal(object): # Use the default time. date = datetime(year=int(date_str), month=1, day=1, hour=self.config['default_hour'], minute=self.config['default_minute']) else: + # clean up some misunderstood dates replacements = (u"september", u"sep"), (u"sept", u"sep"), (u"tuesday", u"tue"), \ (u"tues", u"tue"), (u"thursday", u"thu"), (u"thurs", u"thu"), \ (u" o'clock", u":00") date_str = util.multiple_replace(date_str, *replacements) - try: - date = dateutil.parser.parse(date_str) - flag = 1 if date.hour == 0 and date.minute == 0 else 2 - date = date.timetuple() - except: - date, flag = self.dateparse.parse(date_str) + # determine if we've been given just a month, or just a year and month + replacements2 = ("january", "01"), ("february", "02"), ("march", "03"), \ + ("april", "04"), ("may", "05"), ("june", "06"), \ + ("july", "07"), ("august", "08"), \ + ("october", "10"), ("november", "11"), ("december", "12"), \ + ("jan", "01"), ("feb", "02"), ("mar", "03"), ("apr", "04"), \ + ("jun", "06"), ("jul", "07"), ("aug", "08"), \ + ("sep", "09"), ("oct", "10"), ("nov", "11"), ("dec", "12") + date_str2 = util.multiple_replace(date_str, *replacements2) + year_month_only = False; + matches = re.match(r'^(\d{4})[ \\/-](\d{2})$', date_str2) + if matches: + myYear = matches.group(1) + myMonth = matches.group(2) + year_month_only = True + else: + matches2 = re.match(r'^(\d{2})[ \\/-](\d{4})$', date_str2) + if matches2: + myYear = matches2.group(2) + myMonth = matches2.group(1) + year_month_only = True + else: + matches3 = re.match(r'^(\d{2})$', date_str2) + if matches3: + myYear = datetime.today().year + myMonth = matches3.group(0) - if not flag: # Oops, unparsable. - try: # Try and parse this as a single year - year = int(date_str) - return datetime(year, 1, 1) - except ValueError: - return None - except TypeError: - return None + # if given (just) a month and it's not this month or next, assume it was last year + dt = datetime.now() - datetime(year=int(myYear), month=int(myMonth), day=1) + if dt.days < -32: + myYear = myYear - 1 + year_month_only = True - if flag is 1: # Date found, but no time. + if year_month_only == True: if end_flag == "from": - date = datetime(*date[:3], hour=0, minute=0) + date = datetime(year=int(myYear), month=int(myMonth), day=1, hour=0, minute=0) elif end_flag == "to": - date = datetime(*date[:3], hour=23, minute=59, second=59) + # get the last day of the month + if myMouth == 12: + date = datetime(year=int(myYear), month=int(myMonth), day=31, hour=23, minute=59, second=59) + else: + date = datetime(year=int(myYear), month=int(myMonth)+1, day=1, hour=23, minute=59, second=59) - timedelta (days = 1) else: # Use the default time. - date = datetime(*date[:3], hour=self.config['default_hour'], minute=self.config['default_minute']) - else: - date = datetime(*date[:6]) + date = datetime(year=int(myYear), month=int(myMonth), day=1, hour=self.config['default_hour'], minute=self.config['default_minute']) - # Ugly heuristic: if the date is more than 4 weeks in the future, we got the year wrong. - # 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: - date = date.replace(date.year - 1) + else: + try: + date = dateutil.parser.parse(date_str) + flag = 1 if date.hour == 0 and date.minute == 0 else 2 + date = date.timetuple() + except: + date, flag = self.dateparse.parse(date_str) + + if not flag: # Oops, unparsable. + try: # Try and parse this as a single year + year = int(date_str) + return datetime(year, 1, 1) + except ValueError: + return None + except TypeError: + return None + + if flag is 1: # Date found, but no time. + if end_flag == "from": + date = datetime(*date[:3], hour=0, minute=0) + elif end_flag == "to": + date = datetime(*date[:3], hour=23, minute=59, second=59) + else: + # Use the default time. + date = datetime(*date[:3], hour=self.config['default_hour'], minute=self.config['default_minute']) + else: + date = datetime(*date[:6]) + + # Ugly heuristic: if the date is more than 4 weeks in the future, we got the year wrong. + # 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: + date = date.replace(date.year - 1) return date From 797a8b143e797cdcfe92753985a054a68d1a8f47 Mon Sep 17 00:00:00 2001 From: William Minchin Date: Mon, 10 Feb 2014 13:56:38 -0700 Subject: [PATCH 11/12] Split out (failing) test These tests have a date with a period in it --- features/dates2.feature | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/features/dates2.feature b/features/dates2.feature index 1b51e55b..ae543cde 100644 --- a/features/dates2.feature +++ b/features/dates2.feature @@ -38,16 +38,12 @@ Feature: Processing of (fixed) dates and times | 2013-may-07 08:12 | 2013-05-07 08:12 | 76 | | 2013-may-07 20:13 | 2013-05-07 20:13 | 77 | - Examples: Full dates, with written montsh + Examples: Full dates, with written months | date in | date out | entry no | | Feb 5, 2014 | 2014-02-05 09:00 | 78 | | Feb 06, 2014 | 2014-02-06 09:00 | 79 | - | Feb. 7, 2014 | 2014-02-07 09:00 | 80 | - | Feb. 08, 2014 | 2014-02-08 09:00 | 81 | | 9 Feb 2014 | 2014-02-09 09:00 | 82 | | 01 Feb 2014 | 2014-02-01 09:00 | 83 | - | 2 Feb. 2014 | 2014-02-02 09:00 | 84 | - | 03 Feb. 2014 | 2014-02-03 09:00 | 85 | Examples: 'YYYY/MM/DD' dates (with and without times) | date in | date out | entry no | @@ -62,3 +58,17 @@ Feature: Processing of (fixed) dates and times | 13/06/2007 8:11 | 2007-06-13 08:11 | 91 | | 13/06/2007 08:12 | 2007-06-13 08:12 | 92 | | 13/06/2007 20:13 | 2007-06-13 20:13 | 93 | + + @wip + Scenario Outline: Test all sorts of (fixed) dates with periods + Given we use the config "empty.json" + When we run "jrnl : I saw Elvis . He's Alive!" + Then we should get no error + Then the journal should contain " I saw Elvis " + + Examples: Full dates, with written months, with periods + | date in | date out | entry no | + | Feb. 7, 2014 | 2014-02-07 09:00 | 80 | + | Feb. 08, 2014 | 2014-02-08 09:00 | 81 | + | 2 Feb. 2014 | 2014-02-02 09:00 | 84 | + | 03 Feb. 2014 | 2014-02-03 09:00 | 85 | \ No newline at end of file From e042e8f05861780d8124ae762e4a0eabbfe2ec7b Mon Sep 17 00:00:00 2001 From: William Minchin Date: Mon, 10 Feb 2014 13:56:57 -0700 Subject: [PATCH 12/12] Drop text to lowercase for replacements --- jrnl/Journal.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/jrnl/Journal.py b/jrnl/Journal.py index 4fc62d02..1ee34556 100644 --- a/jrnl/Journal.py +++ b/jrnl/Journal.py @@ -259,7 +259,7 @@ class Journal(object): replacements = (u"september", u"sep"), (u"sept", u"sep"), (u"tuesday", u"tue"), \ (u"tues", u"tue"), (u"thursday", u"thu"), (u"thurs", u"thu"), \ (u" o'clock", u":00") - date_str = util.multiple_replace(date_str, *replacements) + date_str = util.multiple_replace(date_str.lower(), *replacements) # determine if we've been given just a month, or just a year and month replacements2 = ("january", "01"), ("february", "02"), ("march", "03"), \ @@ -269,7 +269,7 @@ class Journal(object): ("jan", "01"), ("feb", "02"), ("mar", "03"), ("apr", "04"), \ ("jun", "06"), ("jul", "07"), ("aug", "08"), \ ("sep", "09"), ("oct", "10"), ("nov", "11"), ("dec", "12") - date_str2 = util.multiple_replace(date_str, *replacements2) + date_str2 = util.multiple_replace(date_str.lower(), *replacements2) year_month_only = False; matches = re.match(r'^(\d{4})[ \\/-](\d{2})$', date_str2) if matches: @@ -299,7 +299,7 @@ class Journal(object): date = datetime(year=int(myYear), month=int(myMonth), day=1, hour=0, minute=0) elif end_flag == "to": # get the last day of the month - if myMouth == 12: + if myMonth == 12: date = datetime(year=int(myYear), month=int(myMonth), day=31, hour=23, minute=59, second=59) else: date = datetime(year=int(myYear), month=int(myMonth)+1, day=1, hour=23, minute=59, second=59) - timedelta (days = 1)