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

fixed circular import

parent 98de1aed
No related branches found
No related tags found
No related merge requests found
Pipeline #62413 failed with stages
in 1 minute and 16 seconds
__version__ = '2.25.6a3' __version__ = '2.25.6a4'
...@@ -18,7 +18,8 @@ _TIME_MODIFIERS = [ ...@@ -18,7 +18,8 @@ _TIME_MODIFIERS = [
('d', 24 * 60 * 60), ('d', 24 * 60 * 60),
('w', 7 * 24 * 60 * 60) ('w', 7 * 24 * 60 * 60)
] ]
def _parse_time_string(s: tp.Union[int, float, str]) -> float:
def _parse_time_string(s: tp.Union[int, float, str]) -> tp.Union[int, float]:
""" """
Parse a time string into seconds, so eg. '30m' will be equal to 1800, and so will Parse a time string into seconds, so eg. '30m' will be equal to 1800, and so will
be '30 min'. be '30 min'.
...@@ -42,7 +43,7 @@ def _parse_time_string(s: tp.Union[int, float, str]) -> float: ...@@ -42,7 +43,7 @@ def _parse_time_string(s: tp.Union[int, float, str]) -> float:
if modifier in s: if modifier in s:
return float(s[:s.index(modifier)]) * multiple return float(s[:s.index(modifier)]) * multiple
return float(s) return float(s) if float(int(s)) != int(s) else int(s)
class CacheDict(tp.Mapping[K, V]): class CacheDict(tp.Mapping[K, V]):
......
...@@ -9,7 +9,7 @@ TIME_MODIFIERS = [ ...@@ -9,7 +9,7 @@ TIME_MODIFIERS = [
] ]
def parse_time_string(s: tp.Union[int, float, str]) -> float: def parse_time_string(s: tp.Union[int, float, str]) -> tp.Union[int, float]:
""" """
Parse a time string into seconds, so eg. '30m' will be equal to 1800, and so will Parse a time string into seconds, so eg. '30m' will be equal to 1800, and so will
be '30 min'. be '30 min'.
...@@ -24,13 +24,14 @@ def parse_time_string(s: tp.Union[int, float, str]) -> float: ...@@ -24,13 +24,14 @@ def parse_time_string(s: tp.Union[int, float, str]) -> float:
.. warning:: This does not handle fractions of a second! .. warning:: This does not handle fractions of a second!
:param s: time string or time value in seconds :param s: time string or time value in seconds
:return: value in seconds :return: value in seconds (an int)
""" """
if isinstance(s, (int, float)): if isinstance(s, (int, float)):
return s return int(s)
for modifier, multiple in TIME_MODIFIERS: for modifier, multiple in TIME_MODIFIERS:
if modifier in s: if modifier in s:
return float(s[:s.index(modifier)]) * multiple return float(s[:s.index(modifier)]) * multiple
return float(s) return float(s) if float(int(s)) != int(s) else int(s)
...@@ -14,6 +14,12 @@ from satella.warnings import mark_temporarily_disabled ...@@ -14,6 +14,12 @@ from satella.warnings import mark_temporarily_disabled
class TestTime(unittest.TestCase): class TestTime(unittest.TestCase):
def test_parse_time(self):
p = parse_time_string('1800s')
self.assertEqual(p, 1800)
p = parse_time_string('1.5s')
self.assertEqual(p, 1.5)
def test_mark_temp_disabled(self): def test_mark_temp_disabled(self):
@mark_temporarily_disabled('Skipped due to skip') @mark_temporarily_disabled('Skipped due to skip')
......
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