o
    ȕhJ                     @  s6  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 deZdQddZdRddZd
ddSddZ	 	!dTdUd'd(Z			 	!	
dVdWd,d-ZdXd/d0ZdYdZd4d5Zd[d6d7Zd\d>d?Zd]dDdEZd^dFdGZ d_dIdJZ!	!	K	Ld`dadOdPZ"d
S )bzYTime 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                   @  s6   e Zd ZdZdZdZdZdZdZdZ	dZ
dddZdS )Unitr   r                     otherr
   returnc                 C  s   | j |j u r| j|jk S tS )N)	__class__valueNotImplemented)selfr    r   J/var/www/Befach/backend/venv/lib/python3.10/site-packages/humanize/time.py__lt__)   s   zUnit.__lt__N)r   r
   r   r
   )__name__
__module____qualname__MICROSECONDSMILLISECONDSSECONDSMINUTESHOURSDAYSMONTHSYEARSr   r   r   r   r   r      s    r   r   dt.datetimec                  C  s   dd l } | j  S )Nr   )datetimenow)dtr   r   r   _now/   s   
r/   deltadt.timedeltac                 C  s    | j dk rt }|||   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   )daysr/   )r0   r-   r   r   r   _abs_timedelta5   s   
	r3   r-   r   r
   r-   dt.datetime | Nonetuple[Any, Any]c             	   C  s   ddl }|s	t }t| |j r| }||  }n-t| |jr#||  }| }n zt| } |j| d}|| }W n ttfyB   d| f Y S w |t|fS )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)r,   r/   
isinstance	timedeltaint
ValueError	TypeErrorr3   )r   r-   r.   dater0   r   r   r   _date_and_deltaD   s"   
r?   Tr8   dt.timedelta | floatmonthsboolminimum_unitstrc              	   C  s  ddl }t|  }|tjtjtjfvrd| d}t||}t| |jr)| }n zt	|  t
| } |j| d}W n ttfyH   t|  Y S w |}t|}|jd }	|jd }
t	|
d }|	s|
dk r|jdkr|tjkr|jd	k rtd
d|j|j S |tjks|tjkrd	|j  krdk rn tdS |jd	 }tddt	|| S tdS |jdkrtdS |jdk rtdd|j|j S d|j  krdk rtdS  d|j  krdk rn n|jd }tdd|| S d|j  krdk rtdS  d|jk r|jd }tdd|| S nk|	dkrF|
dkrtdS |s*tdd|
|
 S |s5tdd|
|
 S |dkr>td S td!d"|| S |	dkr||sU|
sUtd#S |s`td$d%|
|
 S |rt|dkrltd&S td'd(|| S td$d%|
|
 S td)d*|	d+d,t|	 S )-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 supportedr7   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)r,   r   upperr%   r$   r#   r<   r9   r:   r;   floatr=   rD   absr2   r8   microsecondsr   _replacer   )r   rA   rC   r.   tmpmsgmin_unitr0   
use_monthsyearsr2   
num_monthsmillisecondsminuteshoursr   r   r   r   ]   s   (



"










r   "dt.datetime | dt.timedelta | floatfuturewhenc           
      C  s   ddl }t| } t|}|pt }t| |d\}}|du r!t| S t| |j |jfr.||k}|r4tdntd}	t|||}|tdkrHtdS t|	| 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   Nr4   z%s from nowz%s agorL   r-   )	r,   _convert_aware_datetimer/   r?   rD   r9   r:   rb   r   )
r   rn   rA   rC   ro   r.   r-   r>   r0   agor   r   r   r      s   
r   )dt.datetime | dt.timedelta | float | Nonec                 C  s2   ddl }t| |j r| jdur|j |  } | S )zIConvert aware datetime to naive datetime and pass through any other type.r   N)r,   r9   tzinfofromtimestamp	timestamp)r   r.   r   r   r   rp     s   rp   %b %ddt.date | dt.datetimeformatc              	   C  s   ddl }z|| j| j| j} W n ty   t|  Y S  ttfy+   t|  Y S w | |j	  }|j
dkr<tdS |j
dkrEtdS |j
dkrNtdS | |S )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)r,   r>   yearmonthdayAttributeErrorrD   OverflowErrorr<   ry   r2   rb   strftime)r   rx   r.   r0   r   r   r   r   $  s    



r   c              	   C  s   ddl }z|| j| j| j} W n ty   t|  Y S  ttfy+   t|  Y S w t	| |j
  }|jdkr?t| dS t| S )zKLike `naturalday`, but append a year for dates more than ~five months away.r   Ngc@z%b %d %Y)r,   r>   r}   r~   r   r   rD   r   r<   r3   ry   r2   r   )r   r.   r0   r   r   r   r   D  s   

r   r_   divisorunitsuppressIterable[Unit]tuple[float, float]c                 C  s.   ||kr
| | 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   r   r   rC   r   r   r   r   _quotient_and_remainderV  s
   
r   value1value2ratiorf   c                 C  s8   ||kr| ||  dfS ||v rd|| |  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   )r   r   r   r   rf   r   r   r   r   _carry~  s
   r   c                 C  s:   | |v rt D ]}|| kr||vr|  S q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<   )rf   r   r   re   r   r   r   _suitable_minimum_unit  s   r   	set[Unit]c                 C  s.   t |}tD ]}|| kr |S || q|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)rf   r   r   r   r   r   _suppress_lower_units  s   r   r   %0.2fdt.timedelta | int | NoneIterable[str]c           %   
   C  s  t | \}}|du rt| S dd |D }t|  }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 ]h\}}|\}}}|dks|s||krd|  k rdk rn ndnt|} t||| }!ddl}"||kr|"|d dkr|!d|}!n||kr|!dd}!||!t|  q||!|  ||kr! nqt|dkr-|d S d |dd! }#|d! }$td"|#|$f S )#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'

    ```
    Nc                 S  s   h | ]}t |  qS r   )r   r^   ).0sr   r   r   	<setcomp>  s    zprecisedelta.<locals>.<setcomp>rE   rF   iQ rQ   rM   g    .ArG   r   r   rZ   r[   rX   rY   rV   rW   rT   rU   rR   rS   rN   rO   rJ   rK   rH   rI   r   r\   r]   z, r{   z	%s and %s)r?   rD   r   r^   r   r   r2   r8   ra   listr   r   zipreversedr;   r   mathmodfrc   appendr   lenjoinrb   )%r   rC   r   rx   r>   r0   suppress_setrf   r2   secsusecsr#   r$   r%   r&   r'   r(   r)   r*   rh   rA   rl   rk   msecs_unusedfmtstextsr   fmtsingular_txt
plural_txt	fmt_value
_fmt_valuefmt_txtr   headtailr   r   r   r     sn   H



$

r   )r   r+   )r0   r1   r   r1   )r   r
   r-   r5   r   r6   )Tr8   )r   r@   rA   rB   rC   rD   r   rD   )FTr8   N)r   rm   rn   rB   rA   rB   rC   rD   ro   r5   r   rD   )r   rr   r   r
   )rv   )r   rw   rx   rD   r   rD   )r   rw   r   rD   )r   r_   r   r_   r   r   rC   r   r   r   r   r   )r   r_   r   r_   r   r_   r   r   rf   r   r   r   r   r   )rf   r   r   r   r   r   )rf   r   r   r   r   r   )r8   r   r   )
r   r   rC   rD   r   r   rx   rD   r   rD   )#__doc__
__future__r   enumr   	functoolsr   i18nr   rb   r   numberr   TYPE_CHECKINGr,   r.   collections.abcr	   typingr
   __all__r   r/   r3   r?   r   r   rp   r   r   r   r   r   r   r   r   r   r   r   <module>   sL    	

 
1
 

(
'
