B
    CVvgS  ã               @   st   d dl m Z mZ d dlmZ d dlmZ d dlmZ e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)ÚHttpRequest)Únow)ÚrequestÚsession_timeÚcurrent_timeÚreturnc             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 `z`.)	Ú
isinstancer   ÚintÚ	TypeErrorÚtypeÚ__name__ÚuserZ
last_loginÚtotal_seconds)r   r   r	   Úttl© r   úH/tmp/pip-install-o3oxmrkh/django-auto-logout/django_auto_logout/utils.pyÚ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 `z`.Zdjango_auto_logout_last_request)
r   r   r   r   r   r   Úsessionr   Úfromisoformatr   )r   r   r	   r   Zlast_reqr   r   r   Úseconds_until_idle_time_end    s    


r   N)r   r   Útypingr   Zdjango.httpr   Zdjango.utils.timezoner   r   Úfloatr   r   r   r   r   r   Ú<module>   s   

