
    Қj                    D    d Z ddlmZ ddlmZ ddlmZ d	dZd
dZd
dZ	y)u  
Date utilities — month-end-safe arithmetic using dateutil.relativedelta.

Convention (documented here and enforced everywhere in this codebase):
  Jan 31 + 1 month = Feb 28 (or Feb 29 in a leap year) — NOT Mar 3.
  This uses dateutil.relativedelta which naturally clamps to month-end.

All budget cycles, bill recurrence, and amortization projections MUST use
these helpers. No per-module date arithmetic.
    )annotations)daterelativedeltac                     | t        |      z   S )a"  
    Add (or subtract) a whole number of months to a date, clamping to month-end.

    Examples:
        add_months(date(2026, 1, 31), 1)  -> date(2026, 2, 28)
        add_months(date(2026, 3, 31), -1) -> date(2026, 2, 28)
        add_months(date(2026, 2, 28), 1)  -> date(2026, 3, 28)
    )monthsr   )dtr   s     0/var/www/html/financials/app/utils/date_utils.py
add_monthsr      s     V,,,    c                &    | j                  d      S )z2Return the first day of the month containing `dt`.   day)replacer	   s    r
   month_startr      s    ::!:r   c                     | t        d      z   S )z1Return the last day of the month containing `dt`.   r   r   r   s    r
   	month_endr   #   s    "%%%r   N)r	   r   r   intreturnr   )r	   r   r   r   )
__doc__
__future__r   datetimer   dateutil.relativedeltar   r   r   r    r   r
   <module>r      s$   	 #  0	-
&r   