Coverage for /var/srv/projects/api.amasfac.comuna18.com/tmp/venv/lib/python3.9/site-packages/rest_framework_simplejwt/utils.py: 85%

18 statements  

« prev     ^ index     » next       coverage.py v6.4.4, created at 2023-07-17 14:22 -0600

1from calendar import timegm 

2from datetime import datetime 

3 

4from django.conf import settings 

5from django.utils.functional import lazy 

6from django.utils.timezone import is_naive, make_aware, utc 

7 

8 

9def make_utc(dt): 

10 if settings.USE_TZ and is_naive(dt): 10 ↛ 13line 10 didn't jump to line 13, because the condition on line 10 was never false

11 return make_aware(dt, timezone=utc) 

12 

13 return dt 

14 

15 

16def aware_utcnow(): 

17 return make_utc(datetime.utcnow()) 

18 

19 

20def datetime_to_epoch(dt): 

21 return timegm(dt.utctimetuple()) 

22 

23 

24def datetime_from_epoch(ts): 

25 return make_utc(datetime.utcfromtimestamp(ts)) 

26 

27 

28def format_lazy(s, *args, **kwargs): 

29 return s.format(*args, **kwargs) 

30 

31 

32format_lazy = lazy(format_lazy, str)