diff --git a/src/tww/tokenizer.py b/src/tww/tokenizer.py index 7435d4f..f0d8c91 100644 --- a/src/tww/tokenizer.py +++ b/src/tww/tokenizer.py @@ -26,14 +26,14 @@ r_time_in = re.compile('(?:time)?\s*in\s*(.*)', flags=re.IGNORECASE) r_time_since = re.compile('(?:time)?\s*since\s*(.*)', flags=re.IGNORECASE) r_time_until = re.compile('(?:time)?\s*until\s*(.*)', flags=re.IGNORECASE) r_time_between = re.compile('(?:time)?\s*between\s*(.*)\s*and\s*(.*)', flags=re.IGNORECASE) -r_workdays_since = re.compile('(?:workdays|work days)?\s*since\s*(.*)', flags=re.IGNORECASE) -r_workdays_until = re.compile('(?:workdays|work days)?\s*until\s*(.*)', flags=re.IGNORECASE) -r_workdays_between = re.compile('(?:workdays|work days)?\s*between\s*(.*)\s*and\s*(.*)', flags=re.IGNORECASE) -r_workhours_since = re.compile('(?:workhours|work hours)?\s*since\s*(.*)', flags=re.IGNORECASE) -r_workhours_until = re.compile('(?:workhours|work hours)?\s*until\s*(.*)', flags=re.IGNORECASE) -r_workhours_between = re.compile('(?:workhours|work hours)?\s*between\s*(.*)\s*and\s*(.*)', flags=re.IGNORECASE) +r_workdays_since = re.compile('(?:workdays|work days)\s*since\s*(.*)', flags=re.IGNORECASE) +r_workdays_until = re.compile('(?:workdays|work days)\s*until\s*(.*)', flags=re.IGNORECASE) +r_workdays_between = re.compile('(?:workdays|work days)\s*between\s*(.*)\s*and\s*(.*)', flags=re.IGNORECASE) +r_workhours_since = re.compile('(?:workhours|work hours)\s*since\s*(.*)', flags=re.IGNORECASE) +r_workhours_until = re.compile('(?:workhours|work hours)\s*until\s*(.*)', flags=re.IGNORECASE) +r_workhours_between = re.compile('(?:workhours|work hours)\s*between\s*(.*)\s*and\s*(.*)', flags=re.IGNORECASE) r_timezone_translation = re.compile('(.*)?\s(?:in|to)\s(.*)', flags=re.IGNORECASE) -r_timezone = re.compile('(.*)?\s(?:timezone|timezones|tz)', flags=re.IGNORECASE) +r_timezone = re.compile('(.*)\s(?:timezone|timezones|tz)', flags=re.IGNORECASE) r_timezone_2 = re.compile('(?:timezone in|timezones in|tz in|timezone|timezones|tz)\s(.*)?', flags=re.IGNORECASE) diff --git a/src/tww/tww.py b/src/tww/tww.py index e27721e..ee7cf30 100644 --- a/src/tww/tww.py +++ b/src/tww/tww.py @@ -484,9 +484,9 @@ def custom_dt_parse(query): return query -r_next = re.compile('(?:next)?\s*(.*)', flags=re.IGNORECASE) -r_prev = re.compile('(?:last|prev|previous)?\s*(.*)', flags=re.IGNORECASE) -r_this = re.compile('(?:this|that)?\s*(.*)', flags=re.IGNORECASE) +r_next = re.compile('(?:next)\s*(.*)', flags=re.IGNORECASE) +r_prev = re.compile('(?:last|prev|previous)\s*(.*)', flags=re.IGNORECASE) +r_this = re.compile('(?:this|that)\s*(.*)', flags=re.IGNORECASE) def get_local_now_parsed(s): @@ -686,25 +686,24 @@ def time_to_emoji(dt): def workday_diff(start, end, workdays=None): """ Calculates the difference between two dates excluding weekends - - # TODO: doesn't work with Until (i.e. future calculation) """ + if start > end: + start, end = end, start if not workdays: workdays = range(0, 5) td = end - start daygenerator = (start + timedelta(x + 1) for x in range(td.days)) weekdays = sum(1 for day in daygenerator if day.weekday() in workdays) - return timedelta(days=weekdays) + return timedelta(days=weekdays, seconds=td.seconds) def workhours_diff(start, end, workhour_begin="09:00", workhour_end="17:00", workdays=None): """ Calculates the difference between two dates excluding non-workhours This can potentially be very slow for long ranges as it calculates per minute resolution. - - # TODO: doesn't work with Until (i.e. future calculation) - """ + if start > end: + start, end = end, start if not workdays: workdays = range(0, 5)