Fix #1515: Calendar.setDate/setSelectedDate/setCurrentDate preserve hour/minute/second/millis#5117
Merged
Merged
Conversation
The 2015 reporter showed that the UI Calendar component was silently normalising the time-of-day on every setDate / setCurrentDate / setSelectedDate call. MonthView.setSelectedDay and setCurrentDay forcibly reset HOUR_OF_DAY=1, MINUTE/SECOND/MILLISECOND=0 (lines 1184-1188 and 1055-1070 pre-fix) so any caller round-tripping a Date through Calendar lost the time component. The normalisation is load-bearing for the day-cell renderer: the dates[] array stores normalised millis and the highlight code does exact long equality against SELECTED_DAY/currentDay (lines 1122 and 1302), so simply storing the raw millis breaks day highlighting. Add side fields originalSelectedDay / originalCurrentDay that remember the millis the public setter received, separate from the normalised SELECTED_DAY / currentDay used for cell comparison. The public getDate() / getCurrentDate() return the original when one was supplied; setDate/setSelectedDate/setCurrentDate populate it; a user-initiated day-cell tap clears it (because a tap only conveys day, not time-of-day) so we cleanly fall back to the cell millis. Closes #1515. Adds maven/core-unittests/.../CalendarDatePreservationTest.java with five regression cases covering setDate, setSelectedDate, setCurrentDate, midnight (which pre-fix became 01:00 and could roll the day backwards), and day-of-month integrity after the round-trip. Existing CalendarTest stays green; 38 Calendar+date tests overall pass. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
✅ Continuous Quality ReportTest & Coverage
Static Analysis
Generated automatically by the PR CI workflow. |
Collaborator
Author
|
Compared 122 screenshots: 122 matched. Native Android coverage
✅ Native Android screenshot tests passed. Native Android coverage
Benchmark ResultsDetailed Performance Metrics
|
Collaborator
Author
|
Compared 122 screenshots: 122 matched. Benchmark Results
Build and Run Timing
Detailed Performance Metrics
|
Collaborator
Author
|
Compared 122 screenshots: 122 matched. Benchmark Results
Build and Run Timing
Detailed Performance Metrics
|
Contributor
Cloudflare Preview
|
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
Closes #1515. The 2015 reporter found that the UI Calendar component was silently normalising the time-of-day on every
setDate/setSelectedDate/setCurrentDatecall —MonthView.setSelectedDayandsetCurrentDayforcibly resetHOUR_OF_DAY=1,MINUTE=0,SECOND=0,MILLISECOND=0— so any caller round-tripping aDatethroughCalendarlost the time component (and depending on the timezone, sometimes the day too).The constraint
The normalisation is load-bearing for the day-cell renderer: the
dates[]array stores normalised millis and the highlight code does exact long equality againstSELECTED_DAY/currentDay(lines 1122 and 1302). Simply storing the caller's raw millis silently breaks day highlighting.The fix
Add two side fields
originalSelectedDayandoriginalCurrentDaythat remember the millis the public setter received, separate from the normalisedSELECTED_DAY/currentDayused for cell comparison.getDate()andgetCurrentDate()return the cached original when one was supplied, falling back to the normalised value otherwise.setDate/setSelectedDate/setCurrentDatepopulate it.Test plan
CalendarDatePreservationTestwith five cases:setDateround-trips 13:45:30.500.setSelectedDateround-trips 23:59:59.999.setCurrentDateround-trips 09:30:15.250.year/month/day-of-monthof the round-tripped date still match the input.expected: <1773582330500> but was: <1773529200000>, where the only difference is the time-of-day clobber).CalendarTestand the broader 38-test*Calendar*,*Date*sweep stay green.🤖 Generated with Claude Code