| 570 | super().__init__(**state) |
| 571 | |
| 572 | def remaining_delta(self, last_run_at: datetime, tz: tzinfo | None = None, |
| 573 | ffwd: type = ffwd) -> tuple[datetime, Any, datetime]: |
| 574 | # caching global ffwd |
| 575 | last_run_at = self.maybe_make_aware(last_run_at) |
| 576 | now = self.maybe_make_aware(self.now()) |
| 577 | dow_num = last_run_at.isoweekday() % 7 # Sunday is day 0, not day 7 |
| 578 | |
| 579 | execute_this_date = ( |
| 580 | last_run_at.month in self.month_of_year and |
| 581 | last_run_at.day in self.day_of_month and |
| 582 | dow_num in self.day_of_week |
| 583 | ) |
| 584 | |
| 585 | execute_this_hour = ( |
| 586 | execute_this_date and |
| 587 | last_run_at.day == now.day and |
| 588 | last_run_at.month == now.month and |
| 589 | last_run_at.year == now.year and |
| 590 | last_run_at.hour in self.hour and |
| 591 | last_run_at.minute < max(self.minute) |
| 592 | ) |
| 593 | |
| 594 | if execute_this_hour: |
| 595 | next_minute = min(minute for minute in self.minute |
| 596 | if minute > last_run_at.minute) |
| 597 | delta = ffwd(minute=next_minute, second=0, microsecond=0) |
| 598 | else: |
| 599 | next_minute = min(self.minute) |
| 600 | execute_today = (execute_this_date and |
| 601 | last_run_at.hour < max(self.hour)) |
| 602 | |
| 603 | if execute_today: |
| 604 | next_hour = min(hour for hour in self.hour |
| 605 | if hour > last_run_at.hour) |
| 606 | delta = ffwd(hour=next_hour, minute=next_minute, |
| 607 | second=0, microsecond=0) |
| 608 | else: |
| 609 | next_hour = min(self.hour) |
| 610 | all_dom_moy = (self._orig_day_of_month == '*' and |
| 611 | self._orig_month_of_year == '*') |
| 612 | if all_dom_moy: |
| 613 | next_day = min([day for day in self.day_of_week |
| 614 | if day > dow_num] or self.day_of_week) |
| 615 | add_week = next_day == dow_num |
| 616 | |
| 617 | delta = ffwd( |
| 618 | weeks=add_week and 1 or 0, |
| 619 | weekday=(next_day - 1) % 7, |
| 620 | hour=next_hour, |
| 621 | minute=next_minute, |
| 622 | second=0, |
| 623 | microsecond=0, |
| 624 | ) |
| 625 | else: |
| 626 | delta = self._delta_to_next(last_run_at, |
| 627 | next_hour, next_minute) |
| 628 | return self.to_local(last_run_at), delta, self.to_local(now) |
| 629 | |