fix(android): allow dates before 1970 when only maximumDate is set - #1067
Open
huytdps13400 wants to merge 1 commit into
Open
huytdps13400 wants to merge 1 commit into
huytdps13400 wants to merge 1 commit into
Conversation
When only maximumDate is provided, the date change listener clamps the selected date between minDateWithTimeZone and maxDateWithTimeZone. Without a minimumDate, minDateWithTimeZone returned 0 (the Unix epoch), so any earlier date snapped back to 1970-01-01. Return Long.MIN_VALUE instead, mirroring maxDateWithTimeZone returning Long.MAX_VALUE when maximumDate is not set. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Summary
Fixes #935
On Android (API 26+), when
maximumDateis set butminimumDateis not, the user can't pick a date before 1970-01-01. The picker snaps back to the epoch.Root cause: if either bound is set,
RNDatePickerDialogFragmentinstalls anOnDateChangedListenerthat clamps the selected date to[Common.minDateWithTimeZone(args), Common.maxDateWithTimeZone(args)]. WhenmaximumDateis missing,maxDateWithTimeZonereturnsLong.MAX_VALUE. WhenminimumDateis missing,minDateWithTimeZonereturned0, which is the Unix epoch, so every earlier date was clamped to 1970-01-01.Change:
minDateWithTimeZonenow returnsLong.MIN_VALUEwhenminimumDateis not set, the same waymaxDateWithTimeZonereturnsLong.MAX_VALUE. Both call sites (RNDatePickerDialogFragmentandRNMaterialDatePicker) only use the value for clamping or after checking that the key exists. The picker's own lower bound (setMinDate(RNConstants.DEFAULT_MIN_DATE)) is unchanged.Test Plan
I verified this with a local Robolectric test, which I did not include because the repo has no Android unit test setup. I can add it if you want. The test shows
RNDatePickerDialogFragmentwithvalue = 1970-01-02andmaximumDate = 2006-01-01, callsDatePicker#updateDate(1965, 5, 15)(which fires the clamping listener), and checks the date the picker shows. It ran on SDK 26, 28, 30, 33, 34 and 35.maximumDateset, select 1965-06-15minimumDate1990-01-01 andmaximumDateset, select 1965-06-15What's required for testing (prerequisites)?
An Android device or emulator on API 26 or higher.
What are the steps to reproduce (after prerequisites)?
Use
mode="date",value={new Date(1970, 0, 2)},maximumDate={new Date(2006, 0, 1)}and nominimumDate, then try to select a year before 1970.Compatibility
Checklist
README.md(not needed)example/App.js) (not needed)This fix was prepared with AI assistance (Claude Code) and verified locally with the tests above.
🤖 Generated with Claude Code