From 777be7154909e188fc75f708f2406bfadefd5b99 Mon Sep 17 00:00:00 2001 From: Yash <84263676+yxshee@users.noreply.github.com> Date: Sun, 25 Oct 2026 22:37:33 +0000 Subject: [PATCH] Fix documentation examples whose output does not match pendulum 3 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) Claude-Session: https://claude.ai/code/session_01NQDmA3mwGfL83pbg9WQ6ey --- docs/docs/attributes_properties.md | 4 ++-- docs/docs/difference.md | 8 ++++---- docs/docs/duration.md | 18 +++++++++--------- docs/docs/string_formatting.md | 8 ++++---- src/pendulum/date.py | 4 ++-- src/pendulum/datetime.py | 4 ++-- 6 files changed, 23 insertions(+), 23 deletions(-) diff --git a/docs/docs/attributes_properties.md b/docs/docs/attributes_properties.md index 290891e99..270bca4a8 100644 --- a/docs/docs/attributes_properties.md +++ b/docs/docs/attributes_properties.md @@ -23,9 +23,9 @@ Pendulum gives access to more attributes and properties than the default ``datet >>> dt.microsecond 123789 >>> dt.day_of_week -3 + >>> dt.day_of_year -248 +249 >>> dt.week_of_month 1 >>> dt.week_of_year diff --git a/docs/docs/difference.md b/docs/docs/difference.md index 2653f01fd..04abf538e 100644 --- a/docs/docs/difference.md +++ b/docs/docs/difference.md @@ -59,8 +59,8 @@ to the instance and the passed in instance. There are 4 possibilities: * 5 months ago * When comparing a value in the future to default now: - * 1 hour from now - * 5 months from now + * in 1 hour + * in 5 months * When comparing a value in the past to another value: * 1 hour before @@ -70,7 +70,7 @@ to the instance and the passed in instance. There are 4 possibilities: * 1 hour after * 5 months after -You may also pass `True` as a 2nd parameter to remove the modifiers `ago`, `from now`, etc. +You may also pass `True` as a 2nd parameter to remove the modifiers `ago`, `in`, etc. ```python >>> import pendulum @@ -91,7 +91,7 @@ You may also pass `True` as a 2nd parameter to remove the modifiers `ago`, `from '1 month after' >>> pendulum.now().add(seconds=5).diff_for_humans() -'5 seconds from now' +'in a few seconds' >>> pendulum.now().subtract(days=24).diff_for_humans() '3 weeks ago' diff --git a/docs/docs/duration.md b/docs/docs/duration.md index a657d9aef..839dc87f9 100644 --- a/docs/docs/duration.md +++ b/docs/docs/duration.md @@ -123,19 +123,19 @@ you can use the appropriate methods. # Each method returns a float like the native # total_seconds() method >>> it.total_weeks() -168.15490079569113 +285.2977579385483 >>> it.total_days() -1177.0843055698379 +1997.0843055698379 >>> it.total_hours() -28250.02333367611 +47930.02333367611 >>> it.total_minutes() -1695001.4000205665 +2875801.400020567 >>> it.total_seconds() -101700084.001234 +172548084.001234 ``` Similarly, the `in_xxx()` methods return the total duration in each @@ -143,19 +143,19 @@ supported unit as a truncated integer. ```python >>> it.in_weeks() -168 +285 >>> it.in_days() 1997 >>> it.in_hours() -28250 +47930 >>> it.in_minutes() -1695001 +2875801 >>> it.in_seconds() -101700084 +172548084 ``` It also has a handy `in_words()` method, which determines the duration representation when printed. diff --git a/docs/docs/string_formatting.md b/docs/docs/string_formatting.md index 91b95fc40..f4c5365f2 100644 --- a/docs/docs/string_formatting.md +++ b/docs/docs/string_formatting.md @@ -28,12 +28,12 @@ The default string representation is the same as the one returned by the `isofor 'Thu, Dec 25, 1975 2:15 PM' # You can also use the format() method ->>> dt.format('dddd Do [of] MMMM YYYY HH:mm:ss A') +>>> dt.format('dddd Do [of] MMMM YYYY hh:mm:ss A') 'Thursday 25th of December 1975 02:15:16 PM' # Of course, the strftime method is still available ->>> dt.strftime('%A %-d%t of %B %Y %I:%M:%S %p') -'Thursday 25th of December 1975 02:15:16 PM' +>>> dt.strftime('%A %d of %B %Y %I:%M:%S %p') +'Thursday 25 of December 1975 02:15:16 PM' ``` !!!note @@ -57,7 +57,7 @@ The following are methods to display a `DateTime` instance as a common format: 'Thursday, 25-Dec-1975 14:15:16 EST' >>> dt.to_iso8601_string() -'1975-12-25T14:15:16-0500' +'1975-12-25T14:15:16-05:00' >>> dt.to_rfc822_string() 'Thu, 25 Dec 75 14:15:16 -0500' diff --git a/src/pendulum/date.py b/src/pendulum/date.py index cd703d2ed..040b10153 100644 --- a/src/pendulum/date.py +++ b/src/pendulum/date.py @@ -308,8 +308,8 @@ def diff_for_humans( 5 months ago When comparing a value in the future to default now: - 1 day from now - 5 months from now + in 1 day + in 5 months When comparing a value in the past to another value: 1 day before diff --git a/src/pendulum/datetime.py b/src/pendulum/datetime.py index 96aff25b2..6f9a9ff39 100644 --- a/src/pendulum/datetime.py +++ b/src/pendulum/datetime.py @@ -728,8 +728,8 @@ def diff_for_humans( # type: ignore[override] 5 months ago When comparing a value in the future to default now: - 1 day from now - 5 months from now + in 1 day + in 5 months When comparing a value in the past to another value: 1 day before