Skip to content

Commit 489762f

Browse files
authored
Fix routine which runs at a specific time (#199)
* Convert 'sleep' to float in routines * Fix initial routine settings when 'time' < 'now' * Fix added timedelta to calculate 'sleep'
1 parent c205f02 commit 489762f

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

twitchio/ext/routines/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ async def _routine(self, *args, **kwargs) -> None:
318318
break
319319

320320
if self._time:
321-
sleep = self._time + datetime.timedelta(hours=24)
321+
sleep = compute_timedelta(self._time + datetime.timedelta(days=self._completed_loops))
322322
else:
323323
sleep = max((start - datetime.datetime.now(datetime.timezone.utc)).total_seconds() + self._delta, 0)
324324

@@ -395,7 +395,10 @@ def decorator(coro: Callable) -> Routine:
395395
else:
396396
delta = None
397397

398-
if time_ < datetime.datetime.now(time_.tzinfo):
398+
now = datetime.datetime.now(time_.tzinfo)
399+
if time_ < now:
400+
time_ = datetime.datetime.combine(now.date(), time_.time())
401+
if time_ < now:
399402
time_ = time_ + datetime.timedelta(days=1)
400403

401404
if not asyncio.iscoroutinefunction(coro):

0 commit comments

Comments
 (0)