U
    £xaŒ  ã                   @   sŠ   d dl m Z mZ d dlmZ d dlmZ d dlmZ d dlm	Z	 e dœdd„Z
eeeef e ed	œd
d„Zeeeef e edœdd„ZdS )é    )ÚdatetimeÚ	timedelta)ÚUnion)Úsettings)ÚHttpRequest)Útimezone)Úreturnc                   C   s    t jrtjtt jƒd�S t ¡ S )zZ
    Returns the current time with the Django project timezone.
    :return: datetime
    )Útz)r   ZUSE_TZr   Únowr   Z	TIME_ZONE© r   r   úx/var/www/html/staging.mfahmagazine.net/magazine_api/magazine_env/lib/python3.8/site-packages/django_auto_logout/utils.pyr
      s    r
   )ÚrequestÚsession_timeÚcurrent_timer   c                 C   sP   t |tƒr|}n,t |tƒr&t|d�}ntdt|ƒj› d�ƒ‚| jj| |  ¡ S )zî
    Get seconds until the end of the session.
    :param request: django.http.HttpRequest
    :param session_time: int - for seconds | timedelta
    :param current_time: datetime - use django_auto_logout.utils.now
    :return: float
    ©ÚsecondszAAUTO_LOGOUT['SESSION_TIME'] should be `int` or `timedelta`, not `ú`.)	Ú
isinstancer   ÚintÚ	TypeErrorÚtypeÚ__name__ÚuserZ
last_loginÚtotal_seconds)r   r   r   Úttlr   r   r   Úseconds_until_session_end   s    

r   )r   Ú	idle_timer   r   c                 C   sl   t |tƒr|}n,t |tƒr&t|d�}ntdt|ƒj› d�ƒ‚d| jkrXt | jd ¡}n|}|| |  	¡ S )zè
    Get seconds until the end of downtime.
    :param request: django.http.HttpRequest
    :param idle_time: int - for seconds | timedelta
    :param current_time: datetime - use django_auto_logout.utils.now
    :return: float
    r   z>AUTO_LOGOUT['IDLE_TIME'] should be `int` or `timedelta`, not `r   Zdjango_auto_logout_last_request)
r   r   r   r   r   r   Zsessionr   Úfromisoformatr   )r   r   r   r   Zlast_reqr   r   r   Úseconds_until_idle_time_end)   s    


r   N)r   r   Útypingr   Zdjango.confr   Zdjango.httpr   Zpytzr   r
   r   Úfloatr   r   r   r   r   r   Ú<module>   s   
ü
ü