Repository navigation
Conversation
start_of() and end_of() for day and larger units went through set(), which keeps self.fold. When a DST change happens at midnight, fold=0 moved a skipped midnight back into the previous day and fold=1 picked the later of two midnights. Try both folds and keep the earliest (or latest) instant that is still on the requested date. Fixes python-pendulum#1093
|
Friendly ping: the workflow run still needs a maintainer's approval to start. The PR has no conflicts; happy to adjust it. |
|
One boundary regression in the new comparison key: a valid local result can overflow when pendulum.datetime(1, 1, 1, 12, tz=1).start_of("day")
pendulum.datetime(9999, 12, 31, 12, tz=-1).end_of("day")Both return valid local datetimes on master, but raise Could the ordering key use an ordinal-based AI assistance used for this review and reproduction. |
|
Thanks, you're right. The key is now a |
|
Thanks, confirmed on 360599d. The six boundary cases I reported now pass, along with the revised start/end test module (59 passed total). The 24 fixed-offset/named-zone probes also complete without errors. This was Linux/CPython 3.14 with the pure-Python implementation, not a full-suite or hosted-CI check. AI assistance used for the verification. |
Fixes #1093
Pull Request Check List
What
start_of()/end_of()for day, week, month, year, decade and century went throughset(), which keepsself.fold(since #713). When a DST change happens at midnight:now(),from_timestamp()andin_timezone()give for normal times) moved a skipped midnight back into the previous day:pendulum.today("Africa/Cairo")on 2026-04-24 returned2026-04-23 23:00+02:00.pendulum.datetime()) picked the later of two midnights (Havana 2012-11-04 gave00:00-05:00, not00:00-04:00).end_of("day")with fold=0 on a day whose last hour repeats (Cairo 2026-10-29, Santiago 2023-04-01) ended one hour early.How
New
_first_instant()/_last_instant()helpers build the wall time with fold=0 and fold=1, drop a result that left the requested date (skipped time), and return the earliest (start) or latest (end) instant. The instant is compared in UTC terms because same-tzinfo comparisons ignore the offset. Hour/minute/second units are unchanged, so they still stay in the same pass of a repeated hour (the existingtest_*_on_date_before/after_transitiontests still pass).Tests
tests/datetime/test_start_end_of.py(skipped midnight with fold=0 for day and month, repeated midnight with fold=1, repeated last hour with fold=0). All 4 fail on master and pass here.start_of("day")/end_of("day")results that are on the wrong date or not the first/last instant of it; this branch gives 0.tests/test_main.py::test_instance_with_aware_datetime_any_tzinfo, fails the same way on master (local timezone dependent, see Use an explicit generic timezone in instance() tests #1072).ruff format --checkandmypyclean for the changed files.