MCPcopy Create free account
hub / github.com/Keeper-Security/Commander / format_timeout

Function format_timeout

keepercommander/commands/helpers/timeout.py:46–62  ·  view source on GitHub ↗

Format timeout as instance of timedelta for output to console timeout_delta(timedelta): Timeout setting as instance of timedelta. Returns string with value and names of time units separated by commas. If all unit values are zero, then the string '0' is returned.

(timeout_delta)

Source from the content-addressed store, hash-verified

44
45
46def format_timeout(timeout_delta):
47 """Format timeout as instance of timedelta for output to console
48
49 timeout_delta(timedelta): Timeout setting as instance of timedelta.
50 Returns string with value and names of time units separated by commas. If all unit values are zero,
51 then the string '0' is returned.
52 """
53 if timeout_delta == timedelta(0):
54 return '0'
55 else:
56 time_units = {'days': timeout_delta.days}
57 hours_minutes = str(timeout_delta).split(', ')[-1]
58 time_units['hours'], time_units['minutes'], _ = hours_minutes.split(':')
59 for k, v in time_units.items():
60 time_units[k] = int(v)
61 nonzero_units = [f'{v} {k[:-1] if v == 1 else k}' for k, v in time_units.items() if v != 0]
62 return ', '.join(nonzero_units)
63
64
65def enforce_timeout_range(timeout_delta):

Callers 5

test_format_timeoutFunction · 0.90
executeMethod · 0.85
get_device_infoMethod · 0.85
_send_emailMethod · 0.85
enforce_timeout_rangeFunction · 0.85

Calls

no outgoing calls

Tested by 1

test_format_timeoutFunction · 0.72