Skip to content

fix(datetime): keep max when the day overflows - #31489

Open
breken-ai wants to merge 1 commit into
ionic-team:mainfrom
breken-ai:fix/datetime-max-not-mutated
Open

breken-ai wants to merge 1 commit into
ionic-team:mainfrom
breken-ai:fix/datetime-max-not-mutated

Conversation

@breken-ai

Copy link
Copy Markdown

Issue number: resolves #29124


What is the current behavior?

validateParts (core/src/components/datetime/utils/manipulation.ts) clamps the date to min/max first, then fixes a day that does not exist in the month. clampDate returns the minParts / maxParts object itself, not a copy, so the day fix is written into the bound.

With the repro from #29124 (min="2024-03-01T00:00:00", max="2024-04-20T23:59:59"), selecting March 31 and then April on the month wheel calls validateParts({ month: 4, day: 31, year: 2024 }, min, max):

  • clampDate returns this.maxParts
  • numDays(April) = 30 < 31, so maxParts.day = 30

After that, maxParts is April 30, April 21 to 30 are no longer disabled, and the returned date (April 30) is past the real max. The same happens to minParts when the date is before min, e.g. February 31 with min in March sets minParts.day to 29.

What is the new behavior?

  • The day is fixed to the last day of the month first, then the result is clamped, so the fixed day is also checked against min/max.
  • The clamped result is copied, so minParts / maxParts are never changed.
  • The max time check now uses the validated date (like the min check already does), so February 31 with a max of February 29 at 20:00 also gets its time moved back in bounds.

Unit tests in manipulation.spec.ts cover the max case from the issue, the min case, and the max time case.

Red on main (879e91d):

● validateParts() › should not mutate the max parts when the day does not exist in the new month
    -   "day": 20,
    +   "day": 30,
● validateParts() › should not mutate the min parts when the day does not exist in the new month

Green with the fix: npx stencil test --spec -- src/components/datetime/test/ passes 116/116. eslint, prettier --check and tsc --noEmit -p tsconfig.json are clean.

Does this introduce a breaking change?

  • Yes
  • No

Other information

This fix was found and written with an AI coding assistant (Claude Code); the red/green runs above are from this branch.

🤖 Generated with Claude Code

validateParts clamped the date first and then fixed a day that does
not exist in the month. clampDate returns the minParts or maxParts
object itself, so the day fix was written into the bound. Selecting
the 31st and then a shorter month on the wheel moved max to the last
day of that month, and the returned date could be past max.

Fix the day first, then clamp, and copy the clamped result.

Resolves ionic-team#29124

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@breken-ai
breken-ai requested a review from a team as a code owner September 26, 2026 02:41
@breken-ai
breken-ai requested a review from thetaPC September 26, 2026 02:41
@vercel

vercel Bot commented Sep 26, 2026

Copy link
Copy Markdown

@breken-ai is attempting to deploy a commit to the Ionic Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added the package: core @ionic/core package label Sep 26, 2026

This branch has not been deployed

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

Labels

package: core @ionic/core package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: max value changes when selecting the 31st and changing the month through the wheel

1 participant