Skip to content

Fix documentation examples whose output does not match pendulum 3 - #1071

Open
yxshee wants to merge 1 commit into
python-pendulum:masterfrom
yxshee:fix/docs-example-outputs
Open

yxshee wants to merge 1 commit into
python-pendulum:masterfrom
yxshee:fix/docs-example-outputs

Conversation

@yxshee

@yxshee yxshee commented Oct 26, 2026

Copy link
Copy Markdown

Pull Request Check List

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

This only changes documentation (four docs pages and two docstrings), so there are no new tests.

I ran the examples in the docs against master and found some outputs that the current code can't produce. Each fix below was checked by running the code on master (e06dace) with Python 3.13.

attributes_properties.md

  • pendulum.parse('2012-09-05T23:26:11.123789').day_of_week returns <WeekDay.WEDNESDAY: 2>. The docs showed 3, which was the old Sunday-based numbering.
  • day_of_year for that date is 249 (2012 is a leap year, and strftime('%j') agrees). The docs showed 248.

duration.md

The it in the "Properties and Duration Methods" section is duration(years=2, months=3, days=1177, seconds=7284, microseconds=1234). The total_*() and in_*() values were computed for days=1177 alone, but in_days() on the same page already showed 1997. The page's own note says total_seconds() approximates years and months (70848000.0 for 2 years 3 months), and 70848000.0 + 101700084.001234 == 172548084.001234, which is what the code returns. I updated total_weeks/days/hours/minutes/seconds and in_weeks/hours/minutes/seconds to the real values. in_days() was already right.

string_formatting.md

  • dt.format('dddd Do [of] MMMM YYYY HH:mm:ss A') returns 'Thursday 25th of December 1975 14:15:16 PM'. Using hh gives the documented 02:15:16 PM.
  • dt.strftime('%A %-d%t of %B %Y %I:%M:%S %p') returns 'Thursday 25\t of December 1975 02:15:16 PM', because %t is a tab and strftime has no ordinal suffix. I changed it to '%A %d of %B %Y %I:%M:%S %p', which returns 'Thursday 25 of December 1975 02:15:16 PM' and also works on Windows, where %-d isn't supported.
  • to_iso8601_string() for 1975-12-25 14:15:16 in America/New_York returns '1975-12-25T14:15:16-05:00', with a colon in the offset. The docs showed -0500.

difference.md, Date.diff_for_humans() and DateTime.diff_for_humans() docstrings

The English locale formats future values relative to now as in {}, so the result is 'in 1 hour', 'in 5 months' and 'in 1 day', not "... from now". pendulum.now().add(seconds=5).diff_for_humans() returns 'in a few seconds', since anything under 10 seconds is "a few seconds". I also changed "remove the modifiers ago, from now" to ago, in. I checked these with pendulum.travel_to(..., freeze=True) and without freezing too.

I left examples alone when their output depends on the current time or the local timezone.

Several documented outputs cannot be produced by the current code:

- attributes_properties.md: 2012-09-05 is a Wednesday, so day_of_week
  is WeekDay.WEDNESDAY (2) now that the week starts on Monday at 0, and
  it is day 249 of the (leap) year, not 248.
- duration.md: the total_*() and in_*() values were computed for
  days=1177 only, but the `it` in that section also has years=2 and
  months=3. in_days() already showed 1997; the other values now match.
- string_formatting.md: the format() example used HH with A, which
  gives "14:15:16 PM"; hh gives the documented 02:15:16. In strftime(),
  %t is a tab, not an ordinal suffix. to_iso8601_string() uses a colon
  in the offset (-05:00).
- difference.md and the Date/DateTime.diff_for_humans() docstrings:
  future values relative to now read "in 1 hour", not "1 hour from
  now", and a 5 second difference is "in a few seconds".

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NQDmA3mwGfL83pbg9WQ6ey

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