Skip to content
Snippets Groups Projects
Unverified Commit a1901abd authored by Patrick Cloke's avatar Patrick Cloke Committed by GitHub
Browse files

Add documentation and type hints to parse_duration. (#9432)

parent c4a55ac4
No related branches found
No related tags found
No related merge requests found
Add documentation and type hints to `parse_duration`.
......@@ -21,7 +21,7 @@ import os
from collections import OrderedDict
from hashlib import sha256
from textwrap import dedent
from typing import Any, Iterable, List, MutableMapping, Optional
from typing import Any, Iterable, List, MutableMapping, Optional, Union
import attr
import jinja2
......@@ -147,7 +147,20 @@ class Config:
return int(value) * size
@staticmethod
def parse_duration(value):
def parse_duration(value: Union[str, int]) -> int:
"""Convert a duration as a string or integer to a number of milliseconds.
If an integer is provided it is treated as milliseconds and is unchanged.
String durations can have a suffix of 's', 'm', 'h', 'd', 'w', or 'y'.
No suffix is treated as milliseconds.
Args:
value: The duration to parse.
Returns:
The number of milliseconds in the duration.
"""
if isinstance(value, int):
return value
second = 1000
......
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