Skip to content

Commit 4d04c0d

Browse files
author
Daniel Gillet
committed
Small performance improvement to precisedetla
We only try to round the value based on the format provided if we are dealing with the minimum_unit.
1 parent 191f093 commit 4d04c0d

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/humanize/time.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,9 @@ def precisedelta(
607607
for unit, fmt in zip(reversed(Unit), fmts):
608608
singular_txt, plural_txt, fmt_value = fmt
609609

610-
fmt_value = _rounding_by_fmt(format, fmt_value)
610+
if unit == min_unit:
611+
fmt_value = _rounding_by_fmt(format, fmt_value)
612+
611613
if fmt_value > 0 or (not texts and unit == min_unit):
612614
_fmt_value = 2 if 1 < fmt_value < 2 else int(fmt_value)
613615
fmt_txt = _ngettext(singular_txt, plural_txt, _fmt_value)

0 commit comments

Comments
 (0)