Fix time expression parsing (#24696)

pull/24699/head
Anders Melchiorsen 2019-06-22 13:39:33 +02:00 committed by Otto Winter
parent b8acbf3c3a
commit a439e087e1
2 changed files with 3 additions and 3 deletions

View File

@ -221,7 +221,7 @@ def parse_time_expression(parameter: Any, min_value: int, max_value: int) \
if parameter is None or parameter == MATCH_ALL:
res = [x for x in range(min_value, max_value + 1)]
elif isinstance(parameter, str) and parameter.startswith('/'):
parameter = float(parameter[1:])
parameter = int(parameter[1:])
res = [x for x in range(min_value, max_value + 1)
if x % parameter == 0]
elif not hasattr(parameter, '__iter__'):
@ -302,7 +302,7 @@ def find_next_time_expression_time(now: dt.datetime,
next_hour = _lower_bound(hours, result.hour)
if next_hour != result.hour:
# We're in the next hour. Seconds+minutes needs to be reset.
result.replace(second=seconds[0], minute=minutes[0])
result = result.replace(second=seconds[0], minute=minutes[0])
if next_hour is None:
# No minute to match in this day. Roll-over to next day.

View File

@ -213,7 +213,7 @@ def test_find_next_time_expression_time_basic():
assert datetime(2018, 10, 7, 10, 30, 0) == \
find(datetime(2018, 10, 7, 10, 30, 0), '*', '/30', 0)
assert datetime(2018, 10, 7, 12, 30, 30) == \
assert datetime(2018, 10, 7, 12, 0, 30) == \
find(datetime(2018, 10, 7, 10, 30, 0), '/3', '/30', [30, 45])
assert datetime(2018, 10, 8, 5, 0, 0) == \