Skip to content

[fix] DateInput: normalize selected dates to start-of-day to honor max#12295

Merged
sfc-gh-bnisco merged 1 commit intodevelopfrom
bnisco/fix-12293
Aug 22, 2025
Merged

[fix] DateInput: normalize selected dates to start-of-day to honor max#12295
sfc-gh-bnisco merged 1 commit intodevelopfrom
bnisco/fix-12293

Conversation

@sfc-gh-bnisco
Copy link
Copy Markdown
Collaborator

@sfc-gh-bnisco sfc-gh-bnisco commented Aug 22, 2025

Describe your changes

  • Problem: BaseWeb’s quick select returns midday-anchored Date objects (12:00), while our min/max bounds are midnight. Our validation compared full datetimes, so same-day end dates were flagged as > max.
  • Changes:
    • Normalize all selected dates to 00:00 in handleChange before validation and state updates.
    • Normalize stored values in updateWidgetMgrState before validation.
  • Tests:
    • Add unit test asserting a quick-select range ending "today" is accepted with max set to today and no error icon is shown.
    • Stabilize time by mocking moment.now and Date, avoiding fake timers that interfere with BaseWeb popovers.

GitHub Issue Link (if applicable)

Fixes #12293
Ref #10166, #10764

Testing Plan

  • ✅ Unit Tests (JS and/or Python)

Contribution License Agreement

By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.

@sfc-gh-bnisco sfc-gh-bnisco added security-assessment-completed change:bugfix PR contains bug fix implementation impact:users PR changes affect end users labels Aug 22, 2025
@snyk-io
Copy link
Copy Markdown
Contributor

snyk-io bot commented Aug 22, 2025

🎉 Snyk checks have passed. No issues have been found so far.

security/snyk check is complete. No issues have been found. (View Details)

license/snyk check is complete. No issues have been found. (View Details)

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Aug 22, 2025

✅ PR preview is ready!

Name Link
📦 Wheel file https://core-previews.s3-us-west-2.amazonaws.com/pr-12295/streamlit-1.48.1-py3-none-any.whl
🕹️ Preview app pr-12295.streamlit.app (☁️ Deploy here if not accessible)

@sfc-gh-bnisco sfc-gh-bnisco requested a review from Copilot August 22, 2025 16:56
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a date validation issue in the DateInput component where BaseWeb's quick select feature returns Date objects anchored at midday (12:00) while min/max bounds are set to midnight, causing same-day end dates to be incorrectly flagged as exceeding the maximum allowed date.

Key changes:

  • Date normalization: Added normalizeToStartOfDay() function to ensure all selected dates are set to 00:00 before validation
  • Validation updates: Modified both handleChange and updateWidgetMgrState to normalize dates before validation
  • Test coverage: Added comprehensive unit test with time mocking to verify quick select ranges ending "today" are accepted without errors

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
frontend/lib/src/components/widgets/DateInput/DateInput.tsx Added date normalization logic to fix midday vs midnight validation issues
frontend/lib/src/components/widgets/DateInput/DateInput.test.tsx Added test case with Date/moment mocking to verify quick select behavior

@sfc-gh-bnisco sfc-gh-bnisco marked this pull request as ready for review August 22, 2025 17:47
Copy link
Copy Markdown
Collaborator

@lukasmasuch lukasmasuch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@sfc-gh-bnisco sfc-gh-bnisco merged commit 824321a into develop Aug 22, 2025
39 checks passed
@sfc-gh-bnisco sfc-gh-bnisco deleted the bnisco/fix-12293 branch August 22, 2025 22:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:bugfix PR contains bug fix implementation impact:users PR changes affect end users

Projects

None yet

Development

Successfully merging this pull request may close these issues.

st.date_input() date range quick select input inconsistent max_value validation

3 participants