
Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­
<!DOCTYPE html>
<html>
U
    su]aB  ã                   @   sö   d Z ddlZddlZddlmZ ddlmZ ddlm	Z
 ddlmZ dd	d
ddgZeG dd„ deƒƒZdd„ Zdd„ Zddœdd„Zd*edœdd„Zd+edœdd	„Zd,edœdd
„Zedœdd„Zdd „ Zd!d"„ Zd#d$„ Zd%d&„ Zd-edœd)d„ZdS ).zYTime humanizing functions.

These are largely borrowed from Django's `contrib.humanize`.
é    N)ÚEnum)Útotal_orderingé   )Úgettext)ÚngettextÚnaturaldeltaÚnaturaltimeÚ
naturaldayÚnaturaldateÚprecisedeltac                   @   s4   e Zd ZdZdZdZdZdZdZdZ	dZ
d	d
„ ZdS )ÚUnitr   r   é   é   é   é   é   é   c                 C   s   | j |j kr| j|jk S tS ©N)Ú	__class__ÚvalueÚNotImplemented)ÚselfÚother© r   ú>/opt/alt/python38/lib/python3.8/site-packages/humanize/time.pyÚ__lt__#   s    zUnit.__lt__N)Ú__name__Ú
__module__Ú__qualname__ÚMICROSECONDSÚMILLISECONDSÚSECONDSÚMINUTESÚHOURSÚDAYSÚMONTHSÚYEARSr   r   r   r   r   r      s   r   c                   C   s
   t j ¡ S r   )ÚdtÚdatetimeÚnowr   r   r   r   Ú_now)   s    r*   c                 C   s    | j dk rtƒ }|||   S | S )zÓReturn an "absolute" value for a timedelta, always representing a time distance.

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

    Returns:
        datetime.timedelta: Absolute timedelta.
    r   )Údaysr*   )Údeltar)   r   r   r   Úabs_timedelta-   s    	
r-   ©r)   c             	   C   sŒ   |s
t ƒ }t| tjƒr$| }||  }n\t| tjƒr>||  }| }nBz t| ƒ} tj| d�}|| }W n  ttfk
r~   d| f Y S X |t|ƒfS )zˆTurn a value into a date and a timedelta which represents how long ago it was.

    If that's not possible, return `(None, value)`.
    )ÚsecondsN)	r*   Ú
isinstancer'   r(   Ú	timedeltaÚintÚ
ValueErrorÚ	TypeErrorr-   )r   r)   Údater,   r   r   r   Údate_and_delta<   s    
r6   Tr/   )Úreturnc                 C   sÖ  t | ¡  }|t jt jt jfkr0td|› d�ƒ‚|}t| |d�\}}|dkrP| S |}t|jƒ}t|j	ƒ}	|	d }
|	d }	t
|	d ƒ}|
�sæ|	dk �ræ|dk�r|t jkrÆ|jd	k rÆtd
d|jƒ|j S |t jksø|t jk�rd	|j  krôdk �rn n|jd	 }tdd|ƒ| S tdƒS |dk�r,tdƒS |dk �rFtdd|ƒ| S d|  k�r^dk �rjn ntdƒS d|  k�r‚dk �ržn n|d }tdd|ƒ| S d|  k�r¶dk �rÂn ntdƒS d|k �rÒ|d }tdd|ƒ| S nì|
dk�rR|	dk�rtdƒS |�stdd|	ƒ|	 S |�s.tdd|	ƒ|	 S |dk�r@td ƒS td!d"|ƒ| S n€|
dk�rÂ|�sp|	�sptd#ƒS |�s†td$d%|	ƒ|	 S |�r°|dk�ržtd&ƒS td'd(|ƒ| S ntd$d%|	ƒ|	 S ntd)d*|
ƒ|
 S d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): 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.
        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 amount of time elapsed.

    Examples
        Compare two timestamps in a custom local timezone::

        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, when=now) == "30 minutes"
    zMinimum unit 'z' not supportedr.   Ném  ç     €>@r   r   éè  ú%d microsecondú%d microsecondsi@B ú%d millisecondú%d millisecondsúa momentza secondé<   ú	%d secondú
%d secondséx   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)r   Úupperr!   r    r   r3   r6   Úabsr/   r+   r2   Úmicrosecondsr   Ú_)r   ÚmonthsÚminimum_unitÚwhenÚtmpr5   r,   Z
use_monthsr/   r+   ÚyearsZmillisecondsÚminutesÚhoursr   r   r   r   S   sŒ    !


ÿÿ
ÿ þþ

ÿÿ







ÿFc           	      C   s€   |pt ƒ }t| |d�\}}|dkr&| S t| tjtjfƒr@||k}|rLtdƒntdƒ}t||||d�}|tdƒkrxtdƒS || 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, int): A `datetime` or a number of seconds.
        future (bool): Ignored for `datetime`s, where the tense is always figured out
            based on the current time. For integers, 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.   Nz%s from nowz%s ago)rU   r?   r)   )r*   r6   r0   r'   r(   r1   rR   r   )	r   ÚfuturerS   rT   rU   r)   r5   r,   Zagor   r   r   r   Â   s    
ú%b %dc              	   C   sš   zt  | j| j| j¡} W n2 tk
r0   |  Y S  ttfk
rJ   |  Y S X | t j ¡  }|j	dkrlt
dƒS |j	dkr~t
dƒS |j	dkr�t
dƒS |  |¡S )zÎReturn 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   Útodayr   ZtomorrowéÿÿÿÿZ	yesterday)r'   r5   ÚyearÚmonthÚdayÚAttributeErrorÚOverflowErrorr3   r\   r+   rR   Ústrftime)r   Úformatr,   r   r   r   r	   ì   s    



c              	   C   sz   zt  | j| j| j¡} W n2 tk
r0   |  Y S  ttfk
rJ   |  Y S X t| t j 	¡  ƒ}|j
dkrrt| dƒS t| ƒS )zKLike `naturalday`, but append a year for dates more than ~five months away.g«ªªªªc@z%b %d %Y)r'   r5   r^   r_   r`   ra   rb   r3   r-   r\   r+   r	   )r   r,   r   r   r   r
     s    


c                 C   s2   ||kr| | dfS ||kr$d| fS t | |ƒS d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   N)Údivmod)r   ZdivisorÚunitrT   Úsuppressr   r   r   Ú_quotient_and_remainder  s
    rh   c                 C   s<   ||kr| ||  dfS ||kr0d|| |  fS | |fS d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   Nr   )Zvalue1Zvalue2Zratiorf   Úmin_unitrg   r   r   r   Ú_carry7  s
    rj   c                 C   s6   | |kr2t D ]}|| kr||kr|  S qtdƒ‚| 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 greather 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   r3   )ri   rg   rf   r   r   r   Ú_suitable_minimum_unitV  s    
ÿrk   c                 C   s,   t |ƒ}tD ]}|| kr q(| |¡ 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)ri   rg   Úur   r   r   Ú_suppress_lower_unitst  s    ro   r   ú%0.2fc           !   
   C   s2  t | ƒ\}}|dkr| 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 ]‚\}}|\}}} | dk�sš|�sÞ||k�rÞt||| ƒ}||k�rÐt | ¡d dk�rÐ| d|¡}| ||  ¡ ||k�rn �qò�qnt|ƒ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   g | ]}t | ¡  ‘qS r   )r   rO   )Ú.0Úsr   r   r   Ú
<listcomp>Ë  s     z precisedelta.<locals>.<listcomp>r8   r9   i€Q rD   r@   g    €„.Ar:   r   r   rM   rN   rK   rL   rI   rJ   rG   rH   rE   rF   rA   rB   r=   r>   r;   r<   z%dz, r]   z	%s and %s)r6   r   rO   rk   ro   r+   r/   rQ   Úlistrh   rj   ÚzipÚreversedr   ÚmathÚmodfÚreplaceÚappendÚlenÚjoinrR   )!r   rT   rg   rd   r5   r,   ri   r+   ZsecsZusecsr   r    r!   r"   r#   r$   r%   r&   rW   rS   rY   rX   ÚmsecsZ_unusedZfmtsZtextsrf   ÚfmtZsingular_txtZ
plural_txtZfmt_txtÚheadÚtailr   r   r   r   „  sh    C

ÿ    ÿø


)Tr/   N)FTr/   N)r[   )r/   r   rp   )Ú__doc__r(   r'   rw   Úenumr   Ú	functoolsr   Zi18nr   rR   r   Ú__all__r   r*   r-   r6   Ústrr   r   r	   r
   rh   rj   rk   ro   r   r   r   r   r   Ú<module>   sJ   û	   üûq    ûú*!