Skip to content
Snippets Groups Projects
Unverified Commit 98de1aed authored by Piotr Maślanka's avatar Piotr Maślanka
Browse files

fix build

parent ee4bfd22
No related branches found
No related tags found
No related merge requests found
Pipeline #62422 passed with stages
in 1 minute and 52 seconds
...@@ -11,6 +11,39 @@ from satella.coding.typing import K, V, NoArgCallable ...@@ -11,6 +11,39 @@ from satella.coding.typing import K, V, NoArgCallable
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
_TIME_MODIFIERS = [
('s', 1),
('m', 60),
('h', 60 * 60),
('d', 24 * 60 * 60),
('w', 7 * 24 * 60 * 60)
]
def _parse_time_string(s: tp.Union[int, float, str]) -> float:
"""
Parse a time string into seconds, so eg. '30m' will be equal to 1800, and so will
be '30 min'.
This will correctly parse:
- seconds
- minutes
- hours
- days
- weeks
.. warning:: This does not handle fractions of a second!
:param s: time string or time value in seconds
:return: value in seconds
"""
if isinstance(s, (int, float)):
return s
for modifier, multiple in _TIME_MODIFIERS:
if modifier in s:
return float(s[:s.index(modifier)]) * multiple
return float(s)
class CacheDict(tp.Mapping[K, V]): class CacheDict(tp.Mapping[K, V]):
""" """
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment