Fixed some bugs

This commit is contained in:
mrhanky
2017-08-16 14:39:44 +02:00
parent f8c51c9242
commit 3808ac60d2
6 changed files with 55 additions and 38 deletions

View File

@@ -23,14 +23,25 @@ def date_from_iso(date: str) -> datetime:
def time_delta(text: str) -> timedelta:
match = re.match(r'(\d+)(s|m|h|mon|w|y)', text)
match = re.match(r'(\d+)(s|m|h|d|mon|w|y)', text)
if match:
num, unit = match.groups()
num = int(num)
unit = TIME_UNITS[unit]
if unit == 'mon':
if unit == 's':
unit = 'seconds'
elif unit == 'm':
unit = 'minutes'
elif unit == 'h':
unit = 'hours'
elif unit == 'd':
unit = 'days'
elif unit == 'w':
unit = 'weeks'
elif unit == 'mon':
unit = 'weeks'
num *= 4
elif unit == 'y':
unit = 'weeks'
num *= 52
return timedelta(**{unit: num})
@@ -52,4 +63,4 @@ def parse_int(val: str, select: bool = True) -> Tuple[int, str]:
def re_generator(low: int = 5, high: int = 20) -> str:
return 'R{}'.format(''.join('E' for _ in range(random.randint(low, high))))
return 'R{}'.format('E' * random.randint(low, high))