| 123456789101112131415161718 |
- from datetime import date, timedelta
- def month_bounds(month: int, year: int) -> tuple[str, str]:
- start = date(year, month, 1)
- end = date(year + month // 12, month % 12 + 1, 1) - timedelta(days=1)
- return start.isoformat(), end.isoformat()
- def months_in_range(date_from: str, date_to: str) -> list[tuple[int, int]]:
- start = date.fromisoformat(date_from)
- end = date.fromisoformat(date_to)
- months: list[tuple[int, int]] = []
- cur = date(start.year, start.month, 1)
- while cur <= end:
- months.append((cur.month, cur.year))
- cur = date(cur.year + cur.month // 12, cur.month % 12 + 1, 1)
- return months
|