Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix time expression parsing #24696

Merged
merged 1 commit into from Jun 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions homeassistant/util/dt.py
Expand Up @@ -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__'):
Expand Down Expand Up @@ -302,7 +302,7 @@ def _lower_bound(arr: List[int], cmp: int) -> Optional[int]:
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.
Expand Down
2 changes: 1 addition & 1 deletion tests/util/test_dt.py
Expand Up @@ -213,7 +213,7 @@ def find(dt, hour, minute, second):
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) == \
Expand Down