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

28 statements  

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

1import datetime 

2 

3 

4def _get_duration_components(duration): 

5 days = duration.days 

6 seconds = duration.seconds 

7 microseconds = duration.microseconds 

8 

9 minutes = seconds // 60 

10 seconds = seconds % 60 

11 

12 hours = minutes // 60 

13 minutes = minutes % 60 

14 

15 return days, hours, minutes, seconds, microseconds 

16 

17 

18def duration_string(duration): 

19 """Version of str(timedelta) which is not English specific.""" 

20 days, hours, minutes, seconds, microseconds = _get_duration_components(duration) 

21 

22 string = "{:02d}:{:02d}:{:02d}".format(hours, minutes, seconds) 

23 if days: 

24 string = "{} ".format(days) + string 

25 if microseconds: 

26 string += ".{:06d}".format(microseconds) 

27 

28 return string 

29 

30 

31def duration_iso_string(duration): 

32 if duration < datetime.timedelta(0): 

33 sign = "-" 

34 duration *= -1 

35 else: 

36 sign = "" 

37 

38 days, hours, minutes, seconds, microseconds = _get_duration_components(duration) 

39 ms = ".{:06d}".format(microseconds) if microseconds else "" 

40 return "{}P{}DT{:02d}H{:02d}M{:02d}{}S".format( 

41 sign, days, hours, minutes, seconds, ms 

42 ) 

43 

44 

45def duration_microseconds(delta): 

46 return (24 * 60 * 60 * delta.days + delta.seconds) * 1000000 + delta.microseconds