mirror of
https://mau.dev/maunium/synapse.git
synced 2024-12-15 00:33:50 +01:00
Add documentation and type hints to parse_duration. (#9432)
This commit is contained in:
parent
c4a55ac4a4
commit
a1901abd6b
2 changed files with 16 additions and 2 deletions
1
changelog.d/9432.misc
Normal file
1
changelog.d/9432.misc
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Add documentation and type hints to `parse_duration`.
|
|
@ -21,7 +21,7 @@ import os
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from hashlib import sha256
|
from hashlib import sha256
|
||||||
from textwrap import dedent
|
from textwrap import dedent
|
||||||
from typing import Any, Iterable, List, MutableMapping, Optional
|
from typing import Any, Iterable, List, MutableMapping, Optional, Union
|
||||||
|
|
||||||
import attr
|
import attr
|
||||||
import jinja2
|
import jinja2
|
||||||
|
@ -147,7 +147,20 @@ class Config:
|
||||||
return int(value) * size
|
return int(value) * size
|
||||||
|
|
||||||
@staticmethod
|
@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):
|
if isinstance(value, int):
|
||||||
return value
|
return value
|
||||||
second = 1000
|
second = 1000
|
||||||
|
|
Loading…
Reference in a new issue