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   

