diff --git a/mo/util_format.py b/mo/util_format.py index a794ad03a4e94212b3a91cffb14c283e44ffa4cc..5b352aa272b3f01fd4d1a7ee8463feea42849f35 100644 --- a/mo/util_format.py +++ b/mo/util_format.py @@ -15,6 +15,15 @@ def inflect_number(n: int, w1: str, w234: str, wother: str, unitprefix: str = '' return f'{n} {unitprefix}{wother}' +def inflect_by_number(n: int, w1: str, w234: str, wother: str, unitprefix: str = '') -> str: + if n == 1: + return f'{unitprefix}{w1}' + elif 2 <= n <= 4: + return f'{unitprefix}{w234}' + else: + return f'{unitprefix}{wother}' + + def timeformat(dt: datetime) -> str: if dt is None: return '–'