Fix not truncating at minutes the first time in <TimePicker> #24305
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.
Description
Continued from #15495.
Seems like that PR only fixes truncating at minutes the second time and beyond. When first calling
changeDate
, the truncated date is saved in the Component's internal state, but not passed as a argument ofonChange
.The detailed steps are as follow:
<TimePicker>
initializes the date withcurrentTime
or now. which contains seconds like2020-07-31T06:45:35
.45
to46
, andblur
the input.changeDate
updates state with zeroed seconds (2020-07-31T06:46:00
)onChange
is triggered with non-zeroed seconds (2020-07-31T06:46:35
)<TimePicker>
re-renders using the new state as the new date06
to07
.changeDate
triggered, and because state was updated with zeroed seconds,newDate
now also has zeroed seconds (2020-07-31T07:46:00
)Note the 4th step, the component will temporary have a non-zeroed second in the date value.
It's likely that users tend to not only update the time once, normally they would update it multiple times, that's why we didn't notice the bug before 🤔 ?
I'm also trying to refactor this component into function component. The updated implementation should not have this bug, but figured to open a bug fix PR first to get it landed. Will open another PR for the refactor.
How has this been tested?
Added unit test in
test/time.js
.Also can tested in the
<PostSchedule>
component. Create a new post and change the schedule time in the settings, and observe the value in devtools or React devtools.Types of changes
Bug fix
Checklist: