Repository navigation
Fix Date.is_same_day() returning False for a datetime on the same day - #1110
Open
Yasser-Ameur wants to merge 1 commit into
Open
Yasser-Ameur wants to merge 1 commit into
Yasser-Ameur wants to merge 1 commit into
Conversation
Date(2015, 5, 28).is_same_day(datetime(2015, 5, 28, 10)) returned False, although the argument is annotated as date and DateTime already compares calendar days in is_same_day(). Date.is_same_day() used self == dt, and a datetime never compares equal to a date. Compare (year, month, day) of both sides, as is_anniversary() does by normalising its argument. Add datetime and DateTime cases to the tests.
Yasser-Ameur
marked this pull request as ready for review
December 5, 2026 03:56
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.
Date.is_same_day()returnsFalsewhen it is given adatetimeorDateTimeon the same day. The argument is annotated asdate, andDateTime.is_same_day()andDate.is_anniversary()already accept datetimes.Cause
is_same_day()insrc/pendulum/date.pyisreturn self == dt, and adatetimenever compares equal to adate.Change
It compares
(year, month, day)of both sides, which is the ruleDateTime.is_same_day()follows. One line in the library. For an aware argument it uses the wall clock fields it carries and does no timezone conversion. Converting an awareDateTimeto the date's calendar first would be a different rule, and I left that open.Tests
test_is_same_day_with_datetimeintests/date/test_comparison.py: a stdlibdatetime, apendulum.datetimeand an aware Paris midnight on the same day giveTrue, and the next day givesFalsefor both kinds. It fails on master withassert False.Run locally on Python 3.14 against the worktree sources:
pytest -q testsgives 1 failed, 1868 passed, 5 skipped, 1 warning. The one failure istests/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, andruff checkandruff format --checkare clean (ruff 0.14.11).The same suite with
PENDULUM_EXTENSIONS=0gives 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
No documentation describes the old result. This is a bug fix, so it is based on
master.