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
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.