Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate when parameter of naturaldelta #248

Merged
merged 4 commits into from Dec 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/humanize/time.py
Expand Up @@ -173,6 +173,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 @@ -189,6 +191,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