finance-telegram-bot/app/periods.py
2026-07-14 12:21:12 +07:00

18 lines
556 B
Python

from __future__ import annotations
from datetime import datetime, timedelta
def day_bounds(now: datetime) -> tuple[datetime, datetime]:
start = now.replace(hour=0, minute=0, second=0, microsecond=0)
return start, start + timedelta(days=1)
def month_bounds(now: datetime) -> tuple[datetime, datetime]:
start = now.replace(day=1, hour=0, minute=0, second=0, microsecond=0)
if start.month == 12:
end = start.replace(year=start.year + 1, month=1)
else:
end = start.replace(month=start.month + 1)
return start, end