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

Fixed PublishDateTimePicker issue with Now() returning null #68331

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

Mayank-Tripathi32
Copy link
Contributor

Resolves #60281

What?

This PR fixes an issue in the publish date-time picker where clicking the "Now" button was returning null instead of the current datetime, causing incorrect GMT date settings when user switches to next day and back.

Why?

Currently, when users click the "Now" button in the publish date-time picker, the component returns null, which creates an inconsistency with the DatePickerComponent's expected behavior. This results in dates being incorrectly set in GMT format, impacting the accuracy of publish timestamps.

The change is necessary to ensure consistent datetime handling across the application and prevent intermittent parsing issues between component updates.

How?

The implementation modifies the "Now" button click handler to return the current datetime as an ISO string (without timezone information) instead of null. This aligns with the expected input format for both TimePicker and DateTimePicker components.
The change replaces:

onClick: () => onChange?.( null )

with:

const handleNowClick = () => {
    const now = new Date().toISOString().slice(0, 19);
    onChange?.(now);
};

Testing Instructions

  1. Open the post editor
  2. Click on the Post Settings sidebar (gear icon)
  3. Locate the Publish section
  4. Click on the date/time picker to open it
    5.1 Click on future Date then observe that publish has changed to schedule
    5.2 Click the "Now" button in the picker header and observe the publish button
    5.3 Click on future date and then switch to current date manually,
  5. Observe that schedule is changed to publish as expected. (Required behaviour)
  6. Save the post and verify the publish timestamp is accurate

Screencast

Test.Publish.mp4

Copy link

github-actions bot commented Dec 26, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: Mayank-Tripathi32 <[email protected]>
Co-authored-by: t-hamano <[email protected]>
Co-authored-by: tyxla <[email protected]>
Co-authored-by: Mamaduka <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@Mayank-Tripathi32
Copy link
Contributor Author

@t-hamano @youknowriad @mikachan Can you please have a look and review whenever possible 😊 Thank you.

@t-hamano t-hamano added [Type] Bug An existing feature does not function as intended [Feature] Document Settings Document settings experience labels Jan 8, 2025
@t-hamano
Copy link
Contributor

t-hamano commented Jan 8, 2025

Thanks for the PR!

I have one concern with the approach taken in this PR. Could you please confirm this comment?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Document Settings Document settings experience [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Editor: Incorrect save button label when toggling dates to schedule a post
2 participants