Skip to content

Commit f702c1c

Browse files
authored
Merge pull request #248 from carterbox/deprecate-naturaldelta-when
2 parents 49f2cd1 + ec49a2d commit f702c1c

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

src/humanize/time.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ def naturaldelta(
174174
minimum_unit (str): The lowest unit that can be used.
175175
when (datetime.datetime): Point in time relative to which _value_ is
176176
interpreted. Defaults to the current time in the local timezone.
177+
Deprecated in version 3.14; If you need to construct a timedelta,
178+
do it inline as the first argument.
177179
178180
Returns:
179181
str: A natural representation of the amount of time elapsed.
@@ -190,6 +192,14 @@ def naturaldelta(
190192
191193
assert naturaldelta(later, when=now) == "30 minutes"
192194
"""
195+
if when:
196+
warnings.warn(
197+
"The `when` parameter of `naturaldelta()` is deprecated and will be "
198+
"removed in humanize 4.0. If you need to construct a timedelta, "
199+
"do it inline as the first argument.",
200+
DeprecationWarning,
201+
stacklevel=2,
202+
)
193203
tmp = _Unit[minimum_unit.upper()]
194204
if tmp not in (_Unit.SECONDS, _Unit.MILLISECONDS, _Unit.MICROSECONDS):
195205
raise ValueError(f"Minimum unit '{minimum_unit}' not supported")

0 commit comments

Comments
 (0)