
    Ī5hJ                       d Z ddlmZ ddlmZ ddlmZ ddlmZ	 ddlm
Z
 ddlmZ d	Zerdd
lZddlmZ ddlmZ g dZe G d de             ZddZddZd
dd dZ	 	 d!	 	 	 	 	 	 	 d"dZ	 	 	 	 d#	 	 	 	 	 	 	 	 	 	 	 d$dZ	 	 	 	 d%dZd&d'dZd(dZ	 	 	 	 	 	 	 	 	 	 	 	 d)dZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 d*dZd+dZ d,dZ!	 	 	 d-	 	 	 	 	 	 	 	 	 d.dZ"y
)/zYTime humanizing functions.

These are largely borrowed from Django's `contrib.humanize`.
    )annotations)Enum)total_ordering   )_gettext)	_ngettext)intcommaFN)Iterable)Any)naturaldate
naturaldaynaturaldeltanaturaltimeprecisedeltac                  4    e Zd ZdZdZdZdZdZdZdZ	dZ
dd	Zy
)Unitr   r                     c                p    | j                   |j                   u r| j                  |j                  k  S t        S )N)	__class__valueNotImplemented)selfothers     S/var/www/html/Kila-kolis-project/venv/lib/python3.12/site-packages/humanize/time.py__lt__zUnit.__lt__)   s+    >>U__,::++    N)r   r   returnr   )__name__
__module____qualname__MICROSECONDSMILLISECONDSSECONDSMINUTESHOURSDAYSMONTHSYEARSr     r!   r   r   r      s/    LLGGEDFEr!   r   c                 >    dd l } | j                   j                         S )Nr   )datetimenow)dts    r   _nowr3   /   s    ;;??r!   c                H    | j                   dk  rt               }||| z   z
  S | S )zReturn an "absolute" value for a timedelta, always representing a time distance.

    Args:
        delta (datetime.timedelta): Input timedelta.

    Returns:
        datetime.timedelta: Absolute timedelta.
    r   )daysr3   )deltar1   s     r   _abs_timedeltar7   5   s*     zzA~fcEk""Lr!   r1   c               .   ddl }|s
t               }t        | |j                         r| }|| z
  }nBt        | |j                        r|| z
  }| }n$	 t	        |       }  |j                  |       }||z
  }|t        |      fS # t
        t        f$ r d| fcY S w xY w)zTurn a value into a date and a timedelta which represents how long ago it was.

    If that's not possible, return `(None, value)`.
    r   Nseconds)r0   r3   
isinstance	timedeltaint
ValueError	TypeErrorr7   )r   r1   r2   dater6   s        r   _date_and_deltarB   D   s    
 f%%e	E2<<	(U{	JE BLL/E;D &&& I& 	;	s   #A> >BBc                F   ddl }t        |j                            }|t        j                  t        j                  t        j
                  fvrd| d}t        |      |}t        | |j                        r| }n*	 t        |        t        |       }  |j                  |       }|}t        |      }|j                  dz  }	|j                  dz  }
t        |
dz        }|	s|
dk  r|j                  dk(  r|t        j
                  k(  r3|j                   d	k  r$t#        d
d|j                         |j                   z  S |t        j                  k(  s5|t        j
                  k(  rJd	|j                   cxk  rdk  r5n t%        d      S |j                   d	z  }t#        ddt        |            |z  S t%        d      S |j                  dk(  rt%        d      S |j                  dk  r$t#        dd|j                        |j                  z  S d|j                  cxk  rdk  rt%        d      S  d|j                  cxk  rdk  r"n n|j                  dz  }t#        dd|      |z  S d|j                  cxk  rdk  rt%        d      S  d|j                  k  r|j                  dz  }t#        dd|      |z  S |	dk(  rT|
dk(  rt%        d      S |st#        dd|
      |
z  S |st#        dd|
      |
z  S |dk(  rt%        d       S t#        d!d"|      |z  S |	dk(  rS|s|
st%        d#      S |st#        d$d%|
      |
z  S |r |dk(  rt%        d&      S t#        d'd(|      |z  S t#        d$d%|
      |
z  S t#        d)d*|	      j'                  d+d,      t)        |	      z  S # t        t        f$ r t        |       cY S w xY w)-a  Return a natural representation of a timedelta or number of seconds.

    This is similar to `naturaltime`, but does not add tense to the result.

    Args:
        value (datetime.timedelta, int or float): A timedelta or a number of seconds.
        months (bool): If `True`, then a number of months (based on 30.5 days) will be
            used for fuzziness between years.
        minimum_unit (str): The lowest unit that can be used.

    Returns:
        str (str or `value`): A natural representation of the amount of time
            elapsed unless `value` is not datetime.timedelta or cannot be
            converted to int (cannot be float due to 'inf' or 'nan').
            In that case, a `value` is returned unchanged.

    Raises:
        OverflowError: If `value` is too large to convert to datetime.timedelta.

    Examples:
        Compare two timestamps in a custom local timezone::

        ```pycon
        >>> import datetime as dt
        >>> from dateutil.tz import gettz

        >>> berlin = gettz("Europe/Berlin")
        >>> now = dt.datetime.now(tz=berlin)
        >>> later = now + dt.timedelta(minutes=30)

        >>> assert naturaldelta(later - now) == "30 minutes"
        True
        ```

    r   NzMinimum unit 'z' not supportedr:   m       >@r     %d microsecond%d microsecondsi@B %d millisecond%d millisecondsa momentza second<   	%d second
%d secondsx   za minute  	%d minute
%d minutesi   zan hour%d hour%d hoursza day%d day%d daysza month%d month	%d monthsza yearz1 year, %d dayz1 year, %d daysz1 year, 1 monthz1 year, %d monthz1 year, %d months%d year%d years%d%s)r0   r   upperr(   r'   r&   r?   r<   r=   r>   floatr@   strabsr5   r;   microsecondsr   _replacer	   )r   monthsminimum_unitr2   tmpmsgmin_unitr6   
use_monthsyearsr5   
num_monthsmillisecondsminuteshourss                  r   r   r   ]   s   P 
|!!#
$C
4<<!2!2D4E4EFF|nO<oH%&	J%LE BLL/E JJEJJ#E::DTT\"JTAX==A4,,,1C1Cd1J.0A5CUCUV(()
 4,,,D---$%:L:L2Xy2X Z=   %11D8.0A3|CTU"# Z= ==AZ= ==2[,FVV$$Z=  % %--&$&mmr)G[,@7JJ5==+8+Y< , %--MMT)EY
E:UBB	!19W:Xy$7$>>Xy$7$>>?Y<[*=
JJ	!$X;-/@$G$NNQ*++ ,.A:N
 )+<dCdJJY
E2::4FRWXXc I& 	u:	s   :)N N N c                r   ddl }t        |       } t        |      }|xs
 t               }t        | |      \  }}|t	        |       S t        | |j                   |j                  f      r||kD  }|rt        d      n
t        d      }	t        |||      }|t        d      k(  rt        d      S t	        |	|z        S )a  Return a natural representation of a time in a resolution that makes sense.

    This is more or less compatible with Django's `naturaltime` filter.

    Args:
        value (datetime.datetime, datetime.timedelta, int or float): A `datetime`, a
            `timedelta`, or a number of seconds.
        future (bool): Ignored for `datetime`s and `timedelta`s, where the tense is
            always figured out based on the current time. For integers and floats, the
            return value will be past tense by default, unless future is `True`.
        months (bool): If `True`, then a number of months (based on 30.5 days) will be
            used for fuzziness between years.
        minimum_unit (str): The lowest unit that can be used.
        when (datetime.datetime): Point in time relative to which _value_ is
            interpreted.  Defaults to the current time in the local timezone.

    Returns:
        str: A natural representation of the input in a resolution that makes sense.
    r   Nr8   z%s from nowz%s agorK   r1   )	r0   _convert_aware_datetimer3   rB   r_   r<   r=   rb   r   )
r   futurerd   re   whenr2   r1   rA   r6   agos
             r   r   r      s    4 #E*E"4(D
.$&C!%S1KD%|5z%"++r||45$!M
!H+C5E*xsU{r!   c                    ddl }t        | |j                         r5| j                  )|j                   j                  | j	                               } | S )zIConvert aware datetime to naive datetime and pass through any other type.r   N)r0   r<   tzinfofromtimestamp	timestamp)r   r2   s     r   rp   rp     s>     %%%,,*B))%//*;<Lr!   c                   ddl }	  |j                  | j                  | j                  | j                        } | |j                  j                         z
  }|j                  dk(  rt        d      S |j                  dk(  rt        d      S |j                  dk(  rt        d      S | j                  |      S # t
        $ r t        |       cY S t        t        f$ r t        |       cY S w xY w)zReturn a natural day.

    For date values that are tomorrow, today or yesterday compared to
    present day return representing string. Otherwise, return a string
    formatted according to `format`.

    r   Ntodayr   tomorrow	yesterday)r0   rA   yearmonthdayAttributeErrorr_   OverflowErrorr?   ry   r5   rb   strftime)r   formatr2   r6   s       r   r   r   $  s     

EKK; BGGMMO#EzzQzzzQ}zzR~>>&!!#  5z:& 5zs   2B4 4C&
C&%C&c                r   ddl }	  |j                  | j                  | j                  | j                        } t        | |j                  j                         z
        }|j                  dk\  rt        | d      S t        |       S # t
        $ r t        |       cY S t        t        f$ r t        |       cY S w xY w)zKLike `naturalday`, but append a year for dates more than ~five months away.r   Ngc@z%b %d %Y)r0   rA   r}   r~   r   r   r_   r   r?   r7   ry   r5   r   )r   r2   r6   s      r   r   r   D  s    

EKK; 5277==?23Ezz\!%,,e  5z:& 5zs   2B B6B65B6c                B    ||k(  r| |z  dfS ||v rd| fS t        | |      S )a  Divide `value` by `divisor` returning the quotient and remainder.

    If `unit` is `minimum_unit`, makes the quotient a float number and the remainder
    will be zero. The rational is that if `unit` is the unit of the quotient, we cannot
    represent the remainder because it would require a unit smaller than the
    `minimum_unit`.

    >>> from humanize.time import _quotient_and_remainder, Unit
    >>> _quotient_and_remainder(36, 24, Unit.DAYS, Unit.DAYS, [])
    (1.5, 0)

    If unit is in `suppress`, the quotient will be zero and the remainder will be the
    initial value. The idea is that if we cannot use `unit`, we are forced to use a
    lower unit so we cannot do the division.

    >>> _quotient_and_remainder(36, 24, Unit.DAYS, Unit.HOURS, [Unit.DAYS])
    (0, 36)

    In other case return quotient and remainder as `divmod` would do it.

    >>> _quotient_and_remainder(36, 24, Unit.DAYS, Unit.HOURS, [])
    (1, 12)

    r   )divmod)r   divisorunitre   suppresss        r   _quotient_and_remainderr   V  s9    > |w!!x%x%!!r!   c                D    ||k(  r
| ||z  z   dfS ||v r
d|| |z  z   fS | |fS )a  Return a tuple with two values.

    If the unit is in `suppress`, multiply `value1` by `ratio` and add it to `value2`
    (carry to right). The idea is that if we cannot represent `value1` we need to
    represent it in a lower unit.

    >>> from humanize.time import _carry, Unit
    >>> _carry(2, 6, 24, Unit.DAYS, Unit.SECONDS, [Unit.DAYS])
    (0, 54)

    If the unit is the minimum unit, `value2` is divided by `ratio` and added to
    `value1` (carry to left). We assume that `value2` has a lower unit so we need to
    carry it to `value1`.

    >>> _carry(2, 6, 24, Unit.DAYS, Unit.DAYS, [])
    (2.25, 0)

    Otherwise, just return the same input:

    >>> _carry(2, 6, 24, Unit.DAYS, Unit.SECONDS, [])
    (2, 6)
    r   r.   )value1value2ratior   rh   r   s         r   _carryr   ~  sF    < x&))x&6E>)))6>r!   c                Z    | |v r&t         D ]  }|| kD  s	||vs|c S  d}t        |      | S )a  Return a minimum unit suitable that is not suppressed.

    If not suppressed, return the same unit:

    >>> from humanize.time import _suitable_minimum_unit, Unit
    >>> _suitable_minimum_unit(Unit.HOURS, []).name
    'HOURS'

    But if suppressed, find a unit greater than the original one that is not
    suppressed:

    >>> _suitable_minimum_unit(Unit.HOURS, [Unit.HOURS]).name
    'DAYS'

    >>> _suitable_minimum_unit(Unit.HOURS, [Unit.HOURS, Unit.DAYS]).name
    'MONTHS'
    z@Minimum unit is suppressed and no suitable replacement was found)r   r?   )rh   r   r   rg   s       r   _suitable_minimum_unitr     s@    $ 8Dh4x#7  QoOr!   c                d    t        |      }t        D ]  }|| k(  r |S |j                  |        |S )a  Extend suppressed units (if any) with all units lower than the minimum unit.

    >>> from humanize.time import _suppress_lower_units, Unit
    >>> [x.name for x in sorted(_suppress_lower_units(Unit.SECONDS, [Unit.DAYS]))]
    ['MICROSECONDS', 'MILLISECONDS', 'DAYS']
    )setr   add)rh   r   r   s      r   _suppress_lower_unitsr     s>     8}H8 O 	T 
 Or!   c           
        t        |       \  }}|t        |       S |D ch c]  }t        |j                             }}t        |j                            }t	        ||      }~t        ||      }|j                  }	|j                  }
|j                  }t        t              \  }}}}}}}}t        |	d|||      \  }}	t        |	d|||      \  }}	t        |	|
d|||      \  }	}
t        |
d|||      \  }}
t        |
d|||      \  }}
t        |
|d|||      \  }
}t        |d|||      \  }}t        |d	d
|||      \  }}dd|fdd|fdd|	fdd|fdd|fdd|
fdd|fdd|fg}g }t        t        t              |      D ]  \  }}|\  }}} | d	kD  s|s||k(  rd
| cxk  rdk  rn ndn
t        |       }!t        |||!      }"d	dl}#||k(  r*|#j#                  |       d	   d	kD  r|"j%                  d|      }"n5||k(  r0|"j%                  dd      }"|j'                  |"t)        |       z         |j'                  |"| z         ||k(  s n t+        |      d
k(  r|d	   S dj-                  |dd       }$|d   }%t/        d       |$|%fz  S c c}w )!a%  Return a precise representation of a timedelta.

    ```pycon
    >>> import datetime as dt
    >>> from humanize.time import precisedelta

    >>> delta = dt.timedelta(seconds=3633, days=2, microseconds=123000)
    >>> precisedelta(delta)
    '2 days, 1 hour and 33.12 seconds'

    ```

    A custom `format` can be specified to control how the fractional part
    is represented:

    ```pycon
    >>> precisedelta(delta, format="%0.4f")
    '2 days, 1 hour and 33.1230 seconds'

    ```

    Instead, the `minimum_unit` can be changed to have a better resolution;
    the function will still readjust the unit to use the greatest of the
    units that does not lose precision.

    For example setting microseconds but still representing the date with milliseconds:

    ```pycon
    >>> precisedelta(delta, minimum_unit="microseconds")
    '2 days, 1 hour, 33 seconds and 123 milliseconds'

    ```

    If desired, some units can be suppressed: you will not see them represented and the
    time of the other units will be adjusted to keep representing the same timedelta:

    ```pycon
    >>> precisedelta(delta, suppress=['days'])
    '49 hours and 33.12 seconds'

    ```

    Note that microseconds precision is lost if the seconds and all
    the units below are suppressed:

    ```pycon
    >>> delta = dt.timedelta(seconds=90, microseconds=100)
    >>> precisedelta(delta, suppress=['seconds', 'milliseconds', 'microseconds'])
    '1.50 minutes'

    ```

    If the delta is too small to be represented with the minimum unit,
    a value of zero will be returned:

    ```pycon
    >>> delta = dt.timedelta(seconds=1)
    >>> precisedelta(delta, minimum_unit="minutes")
    '0.02 minutes'

    >>> delta = dt.timedelta(seconds=0.1)
    >>> precisedelta(delta, minimum_unit="minutes")
    '0 minutes'

    ```
    NrD   rE   iQ rP   rL   g    .ArF   r   r   rY   rZ   rW   rX   rU   rV   rS   rT   rQ   rR   rM   rN   rI   rJ   rG   rH   r   r[   r\   z, r{   z	%s and %s)rB   r_   r   r]   r   r   r5   r;   ra   listr   r   zipreversedr>   r   mathmodfrc   appendr	   lenjoinrb   )&r   re   r   r   rA   r6   ssuppress_setrh   r5   secsusecsr&   r'   r(   r)   r*   r+   r,   r-   rj   rd   rn   rm   msecs_unusedfmtstextsr   fmtsingular_txt
plural_txt	fmt_value
_fmt_valuefmt_txtr   headtails&                                         r   r   r     s   P "%(KD%|5z-56XDOXL6 L&&()H%h=H )<@L ::D==DEOSPLL,%vu  *$UHlSKE4*4vxVLFD dItX|LJD$)$eX|TKE4+D"gxVMGTuc7HlKKD%*t\8\LE5
 E1axNNE7 
J&	[&)	9d#	J&	lG,	lD)	,e4	,e4	D E$.	c.1+j)q=48+;)/a/S^Jj*EGxDIIi$8$;a$?!//$7!//$5Wx	'::;LL9,-8# /& 5zQQx99U3BZ D9D[>T4L((y 7s   I=)r"   zdt.datetime)r6   dt.timedeltar"   r   )r   r   r1   dt.datetime | Noner"   ztuple[Any, Any])Tr;   )r   zdt.timedelta | floatrd   boolre   r_   r"   r_   )FTr;   N)r   z"dt.datetime | dt.timedelta | floatrq   r   rd   r   re   r_   rr   r   r"   r_   )r   z)dt.datetime | dt.timedelta | float | Noner"   r   )z%b %d)r   dt.date | dt.datetimer   r_   r"   r_   )r   r   r"   r_   )r   r^   r   r^   r   r   re   r   r   Iterable[Unit]r"   tuple[float, float])r   r^   r   r^   r   r^   r   r   rh   r   r   r   r"   r   )rh   r   r   r   r"   r   )rh   r   r   r   r"   z	set[Unit])r;   r.   z%0.2f)
r   zdt.timedelta | int | Nonere   r_   r   zIterable[str]r   r_   r"   r_   )#__doc__
__future__r   enumr   	functoolsr   i18nr   rb   r   numberr	   TYPE_CHECKINGr0   r2   collections.abcr
   typingr   __all__r   r3   r7   rB   r   r   rp   r   r   r   r   r   r   r   r.   r!   r   <module>r      s  
 #  $   ( 4    >B '6 !HYHYHY HY 		HYZ !#.-.. . 	.
 . 	.b4"@$%"%"%" %" 	%"
 %" %"P$$$ $ 	$
 $ $ $N:$ " 	h)$h)h) h) 	h)
 	h)r!   