diff --git a/utils/morning_runner.py b/utils/morning_runner.py index f590b6d..b0ff353 100644 --- a/utils/morning_runner.py +++ b/utils/morning_runner.py @@ -156,6 +156,24 @@ class Scheduler: self._running = False logger.info("Планировщик остановлен") + @staticmethod + def _format_duration(seconds: float) -> str: + """Форматирует секунды в читаемый вид: '1 дн, 8 ч, 57 мин, 50 сек'.""" + days, remainder = divmod(seconds, 86400) + hours, remainder = divmod(remainder, 3600) + minutes, secs = divmod(remainder, 60) + + parts = [] + if days: + parts.append(f"{int(days)} дн") + if hours: + parts.append(f"{int(hours)} ч") + if minutes: + parts.append(f"{int(minutes)} мин") + parts.append(f"{int(secs)} сек") + + return ", ".join(parts) + def _calculate_next_run(self, now: datetime) -> datetime: """Рассчитать время следующего запуска.""" hour, minute = map(int, self.morning_time.split(":")) @@ -173,10 +191,9 @@ class Scheduler: sleep_seconds = (target - now).total_seconds() logger.info( - "Ожидание: target=%s, sleep=%.0f сек (%.0f мин)", + "Ожидание: target=%s, sleep=%s", target.strftime("%Y-%m-%d %H:%M"), - sleep_seconds, - sleep_seconds / 60, + self._format_duration(sleep_seconds), ) # Спим до целевого времени