Skip to content

fix: use calendar-aware year calculation in renew modal to prevent infinite loop - #1125

Closed
tenderdeve wants to merge 1 commit into
ensdomains:mainfrom
tenderdeve:fix/renew-year-input-overflow
Closed

tenderdeve wants to merge 1 commit into
ensdomains:mainfrom
tenderdeve:fix/renew-year-input-overflow

Conversation

@tenderdeve

Copy link
Copy Markdown
Contributor

Summary

  • Fix infinite increment bug in the renew modal when entering large year values (e.g. 1600)
  • Root cause: Feedback loop between a leap-day-ignorant seconds-to-years conversion (Math.floor(seconds / ONE_YEAR) where ONE_YEAR = 365 * 24 * 3600) and a leap-day-aware years-to-seconds conversion (Date.setFullYear()). For large values, the leap day accumulation caused the year count to keep increasing on each render.
  • Fix: Replace the naive secondsToYears floor division with calculateDatesDiff(startDate, endDate).diff.years, which uses calendar-aware date arithmetic consistent with the years-to-seconds path, creating a stable roundtrip.

File: src/components/@molecules/DateSelection/DateSelection.tsx

Fixes #1076

Test plan

  • Enter year value of 1600 in the renew modal — should not keep incrementing
  • Enter normal values (1-10 years) — should work as before
  • Switch between year and date views — should remain consistent

…finite loop

The year input in the renew modal caused an infinite increment for
large values (e.g. 1600) because of a feedback loop between a
leap-day-ignorant seconds-to-years conversion and a leap-day-aware
years-to-seconds conversion. Replace the naive floor division with
calendar-aware date diff arithmetic so the roundtrip is stable.

Fixes ensdomains#1076
@sonarqubecloud

Copy link
Copy Markdown

@LeonmanRolls

Copy link
Copy Markdown
Member

Closing in favour of #1130, which is a re-push of this exact commit from a maintainer branch so CI can run for first-time contributors. Original commit authorship preserved via cherry-pick, so you remain the commit author on the re-submission. Thanks again for the diagnosis and fix, @tenderdeve.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Year input causes infinite increment in renew modal for large values

2 participants