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