seguro-app / appClientes /services /date_utils.py
Facundo
opencode-2
936e949
Raw
History Blame Contribute Delete
468 Bytes
from calendar import monthrange
from datetime import date
def add_months_ymd(value: date, months: int) -> date:
year = value.year + (value.month - 1 + months) // 12
month = (value.month - 1 + months) % 12 + 1
last_day = monthrange(year, month)[1]
return date(year, month, min(value.day, last_day))
def ymd_int(value: date) -> int:
return int(value.strftime("%Y%m%d"))
def ymd_month_str(value: date) -> str:
return value.strftime("%Y-%m")