Skip to content

Commit

Permalink
Merge pull request #248 from carterbox/deprecate-naturaldelta-when
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Dec 15, 2021
2 parents 49f2cd1 + ec49a2d commit f702c1c
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/humanize/time.py
Expand Up @@ -174,6 +174,8 @@ def naturaldelta(
minimum_unit (str): The lowest unit that can be used.
when (datetime.datetime): Point in time relative to which _value_ is
interpreted. Defaults to the current time in the local timezone.
Deprecated in version 3.14; If you need to construct a timedelta,
do it inline as the first argument.
Returns:
str: A natural representation of the amount of time elapsed.
Expand All @@ -190,6 +192,14 @@ def naturaldelta(
assert naturaldelta(later, when=now) == "30 minutes"
"""
if when:
warnings.warn(
"The `when` parameter of `naturaldelta()` is deprecated and will be "
"removed in humanize 4.0. If you need to construct a timedelta, "
"do it inline as the first argument.",
DeprecationWarning,
stacklevel=2,
)
tmp = _Unit[minimum_unit.upper()]
if tmp not in (_Unit.SECONDS, _Unit.MILLISECONDS, _Unit.MICROSECONDS):
raise ValueError(f"Minimum unit '{minimum_unit}' not supported")
Expand Down

0 comments on commit f702c1c

Please sign in to comment.