Skip to content

Commit

Permalink
Bug fix: Pluralize as "1.5 seconds" instead of "1.5 second" (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
xolox committed Nov 30, 2020
1 parent ccbefe5 commit 82d2e55
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
4 changes: 2 additions & 2 deletions humanfriendly/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Tests for the `humanfriendly' package.
#
# Author: Peter Odding <peter.odding@paylogic.eu>
# Last Change: April 19, 2020
# Last Change: November 30, 2020
# URL: https://humanfriendly.readthedocs.io

"""Test suite for the `humanfriendly` package."""
Expand Down Expand Up @@ -441,7 +441,7 @@ def test_format_timespan(self):
# Make sure milliseconds are never shown separately when detailed=False.
# https://github.com/xolox/python-humanfriendly/issues/10
assert '1 minute, 1 second and 100 milliseconds' == format_timespan(61.10, detailed=True)
assert '1 minute and 1.1 second' == format_timespan(61.10, detailed=False)
assert '1 minute and 1.1 seconds' == format_timespan(61.10, detailed=False)
# Test for loss of precision as reported in issue 11:
# https://github.com/xolox/python-humanfriendly/issues/11
assert '1 minute and 0.3 seconds' == format_timespan(60.300)
Expand Down
7 changes: 3 additions & 4 deletions humanfriendly/text.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Human friendly input/output in Python.
#
# Author: Peter Odding <peter@peterodding.com>
# Last Change: March 1, 2020
# Last Change: November 30, 2020
# URL: https://humanfriendly.readthedocs.io

"""
Expand All @@ -20,7 +20,6 @@
"""

# Standard library modules.
import math
import numbers
import random
import re
Expand Down Expand Up @@ -284,11 +283,11 @@ def pluralize(count, singular, plural=None):
:param count: The count (a number).
:param singular: The singular form of the word (a string).
:param plural: The plural form of the word (a string or :data:`None`).
:returns: The count and singular/plural word concatenated (a string).
:returns: The count and singular or plural word concatenated (a string).
"""
if not plural:
plural = singular + 's'
return '%s %s' % (count, singular if math.floor(float(count)) == 1 else plural)
return '%s %s' % (count, singular if float(count) == 1.0 else plural)


def random_string(length=(25, 100), characters=string.ascii_letters):
Expand Down

0 comments on commit 82d2e55

Please sign in to comment.