Day first feature for dates added

This commit is contained in:
Juan Pablo Garcia 2017-12-10 13:52:29 -04:00
parent d7a9518bb2
commit 0ac33effec
2 changed files with 5 additions and 5 deletions

View file

@ -179,8 +179,8 @@ class Journal(object):
If strict is True, all tags must be present in an entry. If false, the If strict is True, all tags must be present in an entry. If false, the
entry is kept if any tag is present.""" entry is kept if any tag is present."""
self.search_tags = set([tag.lower() for tag in tags]) self.search_tags = set([tag.lower() for tag in tags])
end_date = time.parse(end_date, inclusive=True) end_date = time.parse(end_date, inclusive=True, default_hour=self.config['default_hour'], default_minute=self.config['default_minute'], dayfirst=self.config['day_first'])
start_date = time.parse(start_date) start_date = time.parse(start_date, default_hour=self.config['default_hour'], default_minute=self.config['default_minute'], dayfirst=self.config['day_first'])
# If strict mode is on, all tags have to be present in entry # 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 tagged = self.search_tags.issubset if strict else self.search_tags.intersection
@ -208,7 +208,7 @@ class Journal(object):
if not date: if not date:
colon_pos = first_line.find(": ") colon_pos = first_line.find(": ")
if colon_pos > 0: if colon_pos > 0:
date = time.parse(raw[:colon_pos], default_hour=self.config['default_hour'], default_minute=self.config['default_minute']) date = time.parse(raw[:colon_pos], default_hour=self.config['default_hour'], default_minute=self.config['default_minute'], dayfirst=self.config['day_first'])
if date: # Parsed successfully, strip that from the raw text if date: # Parsed successfully, strip that from the raw text
starred = raw[:colon_pos].strip().endswith("*") starred = raw[:colon_pos].strip().endswith("*")
raw = raw[colon_pos + 1:].strip() raw = raw[colon_pos + 1:].strip()

View file

@ -12,7 +12,7 @@ consts.DOWParseStyle = -1 # "Monday" will be either today or the last Monday
CALENDAR = pdt.Calendar(consts) CALENDAR = pdt.Calendar(consts)
def parse(date_str, inclusive=False, default_hour=None, default_minute=None): def parse(date_str, inclusive=False, default_hour=None, default_minute=None, dayfirst=False):
"""Parses a string containing a fuzzy date and returns a datetime.datetime object""" """Parses a string containing a fuzzy date and returns a datetime.datetime object"""
if not date_str: if not date_str:
return None return None
@ -24,7 +24,7 @@ def parse(date_str, inclusive=False, default_hour=None, default_minute=None):
year_present = False year_present = False
while not date: while not date:
try: try:
date = dateparse(date_str, default=default_date) date = dateparse(date_str, default=default_date, dayfirst=dayfirst)
if date.year == FAKE_YEAR: if date.year == FAKE_YEAR:
date = datetime(datetime.now().year, date.timetuple()[1:6]) date = datetime(datetime.now().year, date.timetuple()[1:6])
else: else: