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

Refactor Post Date Relative Time Rendering for Future Dates #62979

Merged
merged 1 commit into from
Jul 2, 2024

Conversation

amitraj2203
Copy link
Contributor

What?

Fixes: #62976

Why?

When you have a Date block on a post, schedule the post to the future, and then preview the post, the Date block shows a past date, even though the editor showed a relative future-tense date.

How?

This PR modifies the post date block's relative time format rendering logic to correctly display future dates using %s from now format alongside existing %s ago handling.

Testing Instructions

  1. Add the Date Block
  2. Select the last option in CHOOSE A FORMAT
  3. Schedule the post for a future date
  4. Preview the post

Screenshots or screencast

Screen.Recording.2024-06-28.at.7.55.55.PM.mov

@amitraj2203 amitraj2203 added [Type] Bug An existing feature does not function as intended [Block] Post Date Affects the Post Date Block labels Jun 28, 2024
@amitraj2203 amitraj2203 requested a review from noisysocks June 28, 2024 14:39
@amitraj2203 amitraj2203 requested a review from ajitbohra as a code owner June 28, 2024 14:39
Copy link

github-actions bot commented Jun 28, 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: amitraj2203 <[email protected]>
Co-authored-by: noisysocks <[email protected]>
Co-authored-by: t-hamano <[email protected]>
Co-authored-by: mrfoxtalbot <[email protected]>

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

Copy link
Member

@noisysocks noisysocks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to update the Comment Date block as well?

@amitraj2203
Copy link
Contributor Author

I don't think so, as this case is only for when a post is scheduled for future date.

@t-hamano t-hamano self-requested a review July 1, 2024 13:42
Copy link
Contributor

@t-hamano t-hamano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

By the way, I noticed a while ago that when the time is displayed in minutes, the editor displays it as "minute/minutes", but the front end uses the abbreviation (min/mins). This is because the human_time_diff() function uses an abbreviation only for "minutes". This issue was addressed by the following core ticket:

https://core.trac.wordpress.org/ticket/61535

Copy link
Member

@noisysocks noisysocks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again @amitraj2203

@amitraj2203 amitraj2203 merged commit 44a82f1 into trunk Jul 2, 2024
71 checks passed
@amitraj2203 amitraj2203 deleted the fix/issue-62976 branch July 2, 2024 04:38
@github-actions github-actions bot added this to the Gutenberg 18.8 milestone Jul 2, 2024
carstingaxion pushed a commit to carstingaxion/gutenberg that referenced this pull request Jul 18, 2024
…es (WordPress#62979)

Co-authored-by: amitraj2203 <[email protected]>
Co-authored-by: noisysocks <[email protected]>
Co-authored-by: t-hamano <[email protected]>
Co-authored-by: mrfoxtalbot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Post Date Affects the Post Date Block [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Scheduled Posts using Post Date set to Relative Time show incorrect date in preview
3 participants