o
    ßdTí  ã                   @   sz   d Z ddlZddlmZmZmZ ddlmZmZ g d¢Z	dd„ Z
d	d
„ Zdd„ Zddd„Zddd„Zddd„Zdd„ ZdS )zZTime humanizing functions.  These are largely borrowed from Django's
``contrib.humanize``.é    N)ÚdatetimeÚ	timedeltaÚdateé   )ÚngettextÚgettext)ÚnaturaldeltaÚnaturaltimeÚ
naturaldayÚnaturaldatec                   C   s   t  ¡ S )N)r   Únow© r   r   ú?/var/www/html/env/lib/python3.10/site-packages/humanize/time.pyÚ_now   s   r   c                 C   s    | j dk rtƒ }|||   S | S )zUReturns an "absolute" value for a timedelta, always representing a
    time distance.r   )Údaysr   )Údeltar   r   r   r   Úabs_timedelta   s   
r   c              	   C   s€   t ƒ }t| tƒr| }||  }n+t| tƒr||  }| }nzt| ƒ} t| d�}|| }W n ttfy9   d| f Y S w |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   ÚintÚ
ValueErrorÚ	TypeErrorr   )Úvaluer   r   r   r   r   r   Údate_and_delta   s   



ÿr   Tc                 C   sò  t ƒ }t| ƒ\}}|du r| S |}t|jƒ}t|jƒ}|d }|d }t|d ƒ}|s‘|dk r‘|dkr7tdƒS |dkr?tdƒS |dk rKtd	d
|ƒ| S d|  krXdk rYtdƒS  d|  krcdk rqn n|d }	tdd|	ƒ|	 S d|  kr~dk rtdƒS  d|k r�|d }
tdd|
ƒ|
 S dS |dkrÁ|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 |dkrñ|sÍ|sÍtdƒS |s×tdd|ƒ| S |ré|dkrátdƒS tdd|ƒ| S tdd|ƒ| S td d!|ƒ| S )"a2  Given a timedelta or a number of seconds, return a natural
    representation of the amount of time elapsed.  This is similar to
    ``naturaltime``, but does not add tense to the result.  If ``months``
    is True, then a number of months (based on 30.5 days) will be used
    for fuzziness between years.Ném  g     €>@r   r   úa momentza secondé<   z	%d secondz
%d secondséx   za minutei  z	%d minutez
%d minutesi   zan hourz%d hourz%d hoursza dayz%d dayz%d daysza monthz%d monthz	%d monthsza yearz1 year, %d dayz1 year, %d daysz1 year, 1 monthz1 year, %d monthz1 year, %d monthsz%d yearz%d years)r   r   Úabsr   r   r   Ú_r   )r   Úmonthsr   r   r   Ú
use_monthsr   r   ÚyearsÚminutesÚhoursr   r   r   r   +   sn   

ÿÿþÿÿr   Fc                 C   sn   t ƒ }t| ƒ\}}|du r| S t| ttfƒr||k}|r tdƒntdƒ}t||ƒ}|tdƒkr3tdƒS || S )a¤  Given a datetime or a number of seconds, return a natural representation
    of that time in a resolution that makes sense.  This is more or less
    compatible with Django's ``naturaltime`` filter.  ``future`` is ignored for
    datetimes, where the tense is always figured out based on the current time.
    If an integer is passed, the return value will be past tense by default,
    unless ``future`` is set to True.Nz%s from nowz%s agor   r   )r   r   r   r   r   r   r   )r   Úfuturer    r   r   r   Úagor   r   r   r	   l   s   
r	   ú%b %dc              	   C   s’   zt | j| j| jƒ} W n ty   |  Y S  ttfy"   |  Y S w | t  ¡  }|jdkr2t	dƒS |jdkr;t	dƒS |jdkrDt	dƒS |  
|¡S )z±For date values that are tomorrow, today or yesterday compared to
    present day returns representing string. Otherwise, returns a string
    formatted according to ``format``.r   Útodayr   ÚtomorrowéÿÿÿÿÚ	yesterday)r   ÚyearÚmonthÚdayÚAttributeErrorÚOverflowErrorr   r(   r   r   Ústrftime)r   Úformatr   r   r   r   r
   ƒ   s   þ



r
   c              	   C   sr   zt | j| j| jƒ} W n ty   |  Y S  ttfy"   |  Y S w t| t  ¡  ƒ}|j	dkr5t
| dƒS t
| ƒS )zRLike naturalday, but will append a year for dates that are a year
    ago or more.r   z%b %d %Y)r   r,   r-   r.   r/   r0   r   r   r(   r   r
   )r   r   r   r   r   r   ˜   s   þ

r   )T)FT)r'   )Ú__doc__Útimer   r   r   Úi18nr   r   r   Ú__all__r   r   r   r   r	   r
   r   r   r   r   r   Ú<module>   s   

A
