feat: align tariff resets to calendar month

This commit is contained in:
3252a8
2026-04-28 15:25:46 +03:00
parent 338008bbd0
commit 258b2f4dec
9 changed files with 193 additions and 37 deletions
+12 -1
View File
@@ -1,4 +1,5 @@
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone
from typing import Optional
def add_months(base_dt: datetime, months_to_add: int) -> datetime:
@@ -25,3 +26,13 @@ def add_months(base_dt: datetime, months_to_add: int) -> datetime:
return base_dt.replace(year=year, month=month, day=clamped_day)
def month_start(base_dt: Optional[datetime] = None) -> datetime:
"""Return the first instant of the month in UTC for a datetime."""
moment = base_dt or datetime.now(timezone.utc)
if moment.tzinfo is None:
moment = moment.replace(tzinfo=timezone.utc)
else:
moment = moment.astimezone(timezone.utc)
return datetime(moment.year, moment.month, 1, tzinfo=timezone.utc)