diff --git a/custom_components/pyscript/trigger.py b/custom_components/pyscript/trigger.py index f0372a7..15a524b 100644 --- a/custom_components/pyscript/trigger.py +++ b/custom_components/pyscript/trigger.py @@ -717,11 +717,12 @@ def timer_trigger_next(cls, time_spec, now, startup_time): elif len(match1) == 3: this_t = cls.parse_date_time(match1[1].strip(), 0, now, startup_time) - if this_t <= now and this_t != startup_time: + day_offset = (now - this_t).days + 1 + if day_offset != 0 and this_t != startup_time: # - # Try tomorrow (won't make a difference if spec has full date) + # Try a day offset (won't make a difference if spec has full date) # - this_t = cls.parse_date_time(match1[1].strip(), 1, now, startup_time) + this_t = cls.parse_date_time(match1[1].strip(), day_offset, now, startup_time) startup = now == this_t and now == startup_time if (now < this_t or startup) and (next_time is None or this_t < next_time): next_time = this_t diff --git a/tests/test_unit_trigger.py b/tests/test_unit_trigger.py index 1e68cb9..4550fd8 100644 --- a/tests/test_unit_trigger.py +++ b/tests/test_unit_trigger.py @@ -209,6 +209,10 @@ def test_timer_active_check(hass, spec, now, expected): [["once(2019/9/1 8:00)"], [None]], [["once(2019/9/1 15:00)"], [dt(2019, 9, 1, 15, 0, 0, 0)]], [["once(15:00)"], [dt(2019, 9, 1, 15, 0, 0, 0)]], + [["once(15:00 + 2d)"], [dt(2019, 9, 1, 15, 0, 0, 0), dt(2019, 9, 2, 15, 0, 0, 0)]], + [["once(15:00 - 48h)"], [dt(2019, 9, 1, 15, 0, 0, 0), dt(2019, 9, 2, 15, 0, 0, 0)]], + [["once(11:00 + 2d)"], [dt(2019, 9, 2, 11, 0, 0, 0), dt(2019, 9, 3, 11, 0, 0, 0)]], + [["once(11:00 - 48h)"], [dt(2019, 9, 2, 11, 0, 0, 0), dt(2019, 9, 3, 11, 0, 0, 0)]], [["once(13:00:0.09)"], [dt(2019, 9, 2, 13, 0, 0, 90000)]], [["once(9:00)"], [dt(2019, 9, 2, 9, 0, 0, 0)]], [["once(wed 9:00)"], [dt(2019, 9, 4, 9, 0, 0, 0)]],