Add Date.get_gregorian_ymd() and fix death anniversary calendar bug#2459
Open
dsblank wants to merge 1 commit into
Open
Add Date.get_gregorian_ymd() and fix death anniversary calendar bug#2459dsblank wants to merge 1 commit into
dsblank wants to merge 1 commit into
Conversation
Date.get_month() and get_day() return raw values in whatever calendar the date was recorded in, so code that pulls month/day from an event date and mixes it with Gregorian year math silently misplaces non-Gregorian dates (e.g. a Persian or Hebrew death date landing on the wrong Gregorian day). The birthday code in NarrativeWeb's calendar already guarded against this by converting to Gregorian first, but the neighboring death anniversary code did not. Add Date.get_gregorian_ymd(), a small wrapper that returns (year, month, day) already converted to the Gregorian calendar, so callers have one obvious method to reach for instead of a two-step convert-then-extract pattern that is easy to forget. Use it to fix the death anniversary calculation in both webreport/calendar.py and webreport/webcal.py.
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.
Original issue found by @javadr on gramps-project/addons-source#974
Summary
Date.get_month()/get_day()return raw values in whatever calendar the date was recorded in. Code that extracts month/day from an event date and mixes it with Gregorian year arithmetic silently misplaces non-Gregorian dates (e.g. a Persian or Hebrew death date landing on the wrong Gregorian day).webreport/calendar.pyandwebreport/webcal.py, the birthday-anniversary code already guarded against this by converting to Gregorian before extracting month/day, but the neighboring death-anniversary code did not — same bug class as a recently-fixed 16-year-old bug in the BirthdaysGramplet addon (proximity sort using raw, non-Gregorian month/day).Date.get_gregorian_ymd(), returning(year, month, day)already converted to Gregorian, so future code has one obvious call instead of a two-step convert-then-extract pattern that's easy to forget.Test plan
GregorianYmdTestingramps/gen/lib/test/date_test.pycovering an already-Gregorian date (identity) and conversions from Persian, Julian, Hebrew, and Islamic calendars.get_gregorian_ymd()reproducing the Persian-new-year scenario from the original bug.python3 -m unittest gramps.gen.lib.test.date_test— 45 passed.black --checkandmypyclean on changed files.🤖 Generated with Claude Code