o
    h                     @   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	 de fddZ
d	ed
eeef de defddZd	edeeef de def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   `/var/www/html/magazine_api/magazine_env/lib/python3.10/site-packages/django_auto_logout/utils.pyr
      s   r
   requestsession_timecurrent_timec                 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   	idle_timec                 C   sl   t |tr|}nt |trt|d}ntdt|j dd| jv r,t| 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   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>   s0    



