Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix not truncating at minutes the first time in <TimePicker> #24305

Merged

Conversation

@kevin940726
Copy link
Member

@kevin940726 kevin940726 commented Jul 31, 2020

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 of onChange.

The detailed steps are as follow:

  1. <TimePicker> initializes the date with currentTime or now. which contains seconds like 2020-07-31T06:45:35.
  2. User updates the time, e.g. updating minutes from 45 to 46, and blur the input.
  3. changeDate updates state with zeroed seconds (2020-07-31T06:46:00)
  4. However, onChange is triggered with non-zeroed seconds (2020-07-31T06:46:35)
  5. <TimePicker> re-renders using the new state as the new date
  6. User updates the time again, e.g. updating hours from 06 to 07.
  7. 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:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR.
Copy link
Contributor

@talldan talldan left a comment

Great work on spotting this issue and tracing it back to #15495. Thanks for also adding the test!

Fix makes sense, and worked well in my manual testing.

@talldan talldan merged commit ab5eedf into WordPress:master Jul 31, 2020
15 checks passed
15 checks passed
Cancel Previous Runs
Details
Check Check
Details
build
Details
Admin - 1
Details
Compare performance with master
Details
pull-request-automation
Details
test (gutenberg-editor-gallery)
Details
test (gutenberg-editor-gallery)
Details
All
Details
JavaScript
Details
Admin - 2
Details
PHP
Details
Admin - 3
Details
Mobile
Details
Admin - 4
Details
@github-actions github-actions bot added this to the Gutenberg 8.7 milestone Jul 31, 2020
@kevin940726 kevin940726 deleted the kevin940726:update/time-picker-zero-seconds branch Jul 31, 2020
@kevin940726 kevin940726 mentioned this pull request Aug 4, 2020
6 of 6 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.