Skip to content

Fix Interval.in_words() singular unit for sub-second intervals - #1109

Open
Yasser-Ameur wants to merge 1 commit into
python-pendulum:masterfrom
Yasser-Ameur:fix/interval-in-words-plural
Open

Yasser-Ameur wants to merge 1 commit into
python-pendulum:masterfrom
Yasser-Ameur:fix/interval-in-words-plural

Conversation

@Yasser-Ameur

Copy link
Copy Markdown

Interval.in_words() prints a singular unit for a sub-second interval, while Duration.in_words() prints the plural.

>>> (pendulum.datetime(2012, 1, 1).add(microseconds=123456) - pendulum.datetime(2012, 1, 1)).in_words()
# before: '0.12 second'
# now:    '0.12 seconds'

Cause

#826 changed the sub-second branch of Duration.in_words() to plural(0). Interval carries its own copy of in_words() in src/pendulum/interval.py, which kept plural(1), and its test asserted the singular.

Change

The branch uses plural(0), exactly as Duration.in_words() does. One line in the library. I did not check other locales; the plural form is whatever Duration already uses for each of them.

Tests

I changed the expectation in test_subseconds in tests/interval/test_in_words.py from "0.12 second" to "0.12 seconds", mirroring the Duration test. It fails on master with assert '0.12 second' == '0.12 seconds'.

Run locally on Python 3.14 against the worktree sources: pytest -q tests gives 1 failed, 1867 passed, 5 skipped, 1 warning. The one failure is tests/test_main.py::test_instance_with_aware_datetime_any_tzinfo, which depends on the host timezone and fails without this change too (open PR #1072 covers it). mypy (strict) reports no issues in 228 source files, and ruff check and ruff format --check are clean (ruff 0.14.11).

The same suite with PENDULUM_EXTENSIONS=0 gives the same result.

Not run: other Python versions. I did not edit CHANGELOG.md, since recent PRs do not touch it.

Pull Request Check List

  • Added tests for changed code.
  • Updated documentation for changed code.

The existing test was updated rather than a new one added. No documentation describes the old output. This is a bug fix, so it is based on master.

Interval.in_words() returned "0.12 second" for an interval of 123456
microseconds, while Duration.in_words() returns "0.12 seconds".

python-pendulum#826 changed the sub-second branch of Duration.in_words() to use
plural(0), but Interval overrides in_words() with its own copy of that
code, which still used plural(1). Its test asserted the old singular.

Use plural(0) in Interval.in_words(), as Duration does, and update the
test expectation to "0.12 seconds".
@Yasser-Ameur
Yasser-Ameur marked this pull request as ready for review December 5, 2026 02:51

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant