HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/env/lib/python3.10/site-packages/humanize/__pycache__/time.cpython-310.pyc
o

we3I�@s:dZddlmZddlZddlZddlZddlZddl	m
Z
ddlmZddlm
Z
ddlmZdd	lmZdd
lmZgd�ZeGdd
�d
e
��ZdRdd�ZdSdd�Zdd�dTdd�Z		dUdVd%d&�Z	'			dWdXd+d,�ZdYd/d0�ZdZd[d4d5�Zd\d6d7�Zd]d>d?�Zd^dEdF�Zd_dGdH�Z d`dJdK�Z!		L	MdadbdPdQ�Z"dS)czYTime humanizing functions.

These are largely borrowed from Django's `contrib.humanize`.
�)�annotationsN)�Enum)�total_ordering)�Any�)�_gettext)�	_ngettext)�intcomma)�naturaldelta�naturaltime�
naturalday�naturaldate�precisedeltac@s6eZdZdZdZdZdZdZdZdZ	dZ
ddd
�ZdS)�Unitrr�������other�
typing.Any�returncCs|j|jur|j|jkStS�N)�	__class__�value�NotImplemented)�selfr�r�F/home/arjun/projects/env/lib/python3.10/site-packages/humanize/time.py�__lt__'szUnit.__lt__N)rrrr)�__name__�
__module__�__qualname__�MICROSECONDS�MILLISECONDS�SECONDS�MINUTES�HOURS�DAYS�MONTHS�YEARSr rrrrrsrr�dt.datetimecCs
tj��Sr)�dt�datetime�nowrrrr�_now-s
r0�delta�dt.timedeltacCs |jdkrt�}|||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)�daysr0)r1r/rrr�_abs_timedelta1s
	r4�r/rrr/�dt.datetime | None�tuple[typing.Any, typing.Any]c	Cs�|st�}t|tj�r|}||}n-t|tj�r||}|}n zt|�}tj|d�}||}Wnttfy>d|fYSw|t|�fS)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)	r0�
isinstancer-r.�	timedelta�int�
ValueError�	TypeErrorr4)rr/�dater1rrr�_date_and_delta@s 
�r@Tr9�dt.timedelta | float�months�bool�minimum_unit�strc	Cs�t|��}|tjtjtjfvrd|�d�}t|��|}t|tj�r%|}nzt	|�}tj|d�}Wntt
fy@t|�YSw|}t|j
�}t|j�}	|	d}
|	d}	t	|	d�}|
s�|	dkr�|dkr�|tjkry|jdkrytd	d
|j�|jS|tjks�|tjkr�d|jkr�dkr�ntd�S|jd}tdd
t	|��|Std�S|dkr�td�S|dkr�tdd|�|Sd|kr�dkr�td�Sd|kr�dkr�nn|d}
tdd|
�|
Sd|kr�dkr�td�Sd|kr�|d}tdd|�|Snk|
dk�r4|	dk�r
td�S|�stdd|	�|	S|�s#tdd|	�|	S|dk�r,td�Std d!|�|S|
dk�rj|�sC|	�sCtd"�S|�sNtd#d$|	�|	S|�rb|dk�rZtd%�Std&d'|�|Std#d$|	�|	Std(d)|
��d*d+�t|
�S),aTReturn 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. 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::

        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"
    zMinimum unit 'z' not supportedr8�m��>@rr���%d microsecond�%d microsecondsi@B�%d millisecond�%d milliseconds�a momentza second�<�	%d second�
%d seconds�xza minute��	%d minute�
%d minutesi zan hour�%d hour�%d hoursza day�%d day�%d daysza month�%d month�	%d monthsza yearz1 year, %d dayz1 year, %d daysz1 year, 1 monthz1 year, %d monthz1 year, %d months�%d year�%d years�%d�%s)r�upperr&r%r$r=r:r-r;r<r>rE�absr9r3�microsecondsr�_�replacer	)rrBrD�tmp�msg�min_unitr1�
use_monthsr9r3�years�
num_months�milliseconds�minutes�hoursrrrr
Ys�#�

��
"
������





��r
F�"dt.datetime | dt.timedelta | float�future�whenc	Cs�t|�}t|�}|pt�}t||d�\}}|durt|�St|tjtjf�r*||k}|r0td�ntd�}t	|||�}|td�krDtd�St||�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.
    r5Nz%s from nowz%s agorMr/)
�_convert_aware_datetimer0r@rEr:r-r.r;rbr
)	rrnrBrDror/r?r1�agorrrr�s
r�)dt.datetime | dt.timedelta | float | NonercCs*t|tj�r|jdurtj�|���}|S)zIConvert aware datetime to naive datetime and pass through any other type.N)r:r-r.�tzinfo�
fromtimestamp�	timestamp)rrrrrpsrp�%b %d�dt.date | dt.datetime�formatc	Cs�zt�|j|j|j�}Wntyt|�YSttfy't|�YSw|tj�	�}|j
dkr8td�S|j
dkrAtd�S|j
dkrJtd�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�tomorrow����	yesterday)
r-r?�year�month�day�AttributeErrorrE�
OverflowErrorr=ryr3rb�strftime)rrxr1rrrrs�



rc	Cs~zt�|j|j|j�}Wntyt|�YSttfy't|�YSwt	|tj�
��}|jdkr;t|d�St|�S)zKLike `naturalday`, but append a year for dates more than ~five months away.g�����c@z%b %d %Y)
r-r?r}r~rr�rEr�r=r4ryr3r)rr1rrrr
3s�

r
�float�divisor�unit�suppress�collections.abc.Iterable[Unit]�tuple[float, float]cCs.||kr
||dfS||vrd|fSt||�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)rr�r�rDr�rrr�_quotient_and_remainderCs

r��value1�value2�ratiorf�typing.Iterable[Unit]cCs8||kr|||dfS||vrd|||fS||fS)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)
    rr)r�r�r�r�rfr�rrr�_carryks
r�cCs:||vrtD]}||kr||vr|Sqd}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)rr=)rfr�r�rerrr�_suitable_minimum_unit�s�r��	set[Unit]cCs.t|�}tD]}||kr|S|�|�q|S)aExtend 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)rfr�r�rrr�_suppress_lower_units�s�r�r�%0.2f�dt.timedelta | int | None�typing.Iterable[str]c$
Cs|t|�\}}|durt|�Sdd�|D�}t|��}t||�}~t||�}|j}|j}	|j}
t	t�\}}}
}}}}}t
|d|||�\}}t
|d|||�\}}t||	d|||�\}}	t
|	d|||�\}}	t
|	d|||�\}}	t|	|
d	|
||�\}	}
t
|
d
|||�\}}
t|
dd|||�\}
}d
d|fdd|fdd|fdd|fdd|fdd|	fdd|fdd|
fg}g}tt
t�|�D]d\}}|\}}}|dks�|�s||k�rd|kr�dkr�nndnt|�} t||| �}!||kr�t�|�ddkr�|!�d|�}!n||k�r|!�dd�}!|�|!t|��q�|�|!|�||k�rnq�t|�dk�r)|dSd �|dd!��}"|d!}#td"�|"|#fS)#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'

    ```
    NcSsh|]}t|���qSr)rr_)�.0�srrr�	<setcomp>szprecisedelta.<locals>.<setcomp>rFrGi�QrRrNg��.ArHrrr[r\rYrZrWrXrUrVrSrTrOrPrKrLrIrJrr]r^z, r{z	%s and %s)r@rErr_r�r�r3r9ra�listr�r��zip�reversedr<r�math�modfrc�appendr	�len�joinrb)$rrDr�rxr?r1�suppress_setrfr3�secs�usecsr$r%r&r'r(r)r*r+rhrBrlrk�msecs�_unused�fmts�textsr��fmt�singular_txt�
plural_txt�	fmt_value�
_fmt_value�fmt_txt�head�tailrrrr�slH

�
��
$

�r)rr,)r1r2rr2)rrr/r6rr7)Tr9)rrArBrCrDrErrE)FTr9N)rrmrnrCrBrCrDrEror6rrE)rrrrr)rv)rrwrxrErrE)rrwrrE)rr�r�r�r�rrDrr�r�rr�)r�r�r�r�r�r�r�rrfrr�r�rr�)rfrr�r�rr)rfrr�r�rr�)r9rr�)
rr�rDrEr�r�rxrErrE)#�__doc__�
__future__r�collections.abc�collectionsr.r-r��typing�enumr�	functoolsrr�i18nrrbr�numberr	�__all__rr0r4r@r
rrprr
r�r�r�r�rrrrr�<module>sN	

���
/	


(
'
�