forked from TrueCloudLab/frostfs-testlib
Refactoring utils with adding several new ones
This commit is contained in:
parent
5568cbd0bf
commit
4fd9d69701
10 changed files with 276 additions and 61 deletions
27
src/frostfs_testlib/utils/datetime_utils.py
Normal file
27
src/frostfs_testlib/utils/datetime_utils.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
# There is place for date time utils functions
|
||||
|
||||
|
||||
def parse_time(value: str) -> int:
|
||||
"""Converts time interval in text form into time interval as number of seconds.
|
||||
|
||||
Args:
|
||||
value: time interval as text.
|
||||
|
||||
Returns:
|
||||
Number of seconds in the parsed time interval.
|
||||
"""
|
||||
value = value.lower()
|
||||
|
||||
for suffix in ["s", "sec"]:
|
||||
if value.endswith(suffix):
|
||||
return int(value[: -len(suffix)])
|
||||
|
||||
for suffix in ["m", "min"]:
|
||||
if value.endswith(suffix):
|
||||
return int(value[: -len(suffix)]) * 60
|
||||
|
||||
for suffix in ["h", "hr", "hour"]:
|
||||
if value.endswith(suffix):
|
||||
return int(value[: -len(suffix)]) * 60 * 60
|
||||
|
||||
raise ValueError(f"Unknown units in time value '{value}'")
|
Loading…
Add table
Add a link
Reference in a new issue