-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Post Date & Comment Date: Add relative date format #62298
Post Date & Comment Date: Add relative date format #62298
Conversation
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Nice, thanks for this @amitraj2203! I don't think it's a good idea to do this by storing <?php
echo date('Time Ago'); // prints: UTC4806UTC AM22024 It's unlikely a user would actually want to use that format string but nonetheless I think it's best for us to not mix this data. One idea is to add a new boolean attribute |
Hi @noisysocks, Screen.Recording.2024-06-05.at.2.23.51.PM.mov |
No I think we should still keep the dropdown as that's a better UI. Just changing the way that those settings are stored. Let me know if you need help. |
Hi @noisysocks! Also, the changes in the DateFormatPicker component are good to go or is there anything else we need to adjust there? |
Sorry @amitraj2203, I've changed my mind 😅 I think your approach of using the My change of heart comes from reading this post by @dmsnell which uses |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks so much for this PR @amitraj2203.
I hope you don't mind I pushed some changes: it now uses 'human-diff'
instead of 'Time Ago'
as the format
value that indicates a relative time, it works in the Comment Date block now as well, and it now ensures that the example date shown is a relatively recent date. I also fixed some minor internationalisation problems.
Hi @amitraj2203, Thank you |
* Adds "Time Ago" option to SelectControl of DateFormatPicker * Update post-date block to have "Time ago" format * Use 'human-diff' as format for relative dates * Add support for relative dates to Comment Date block * Always use a somewhat recent example date --------- Co-authored-by: amitraj2203 <amitraj2203@git.wordpress.org> Co-authored-by: noisysocks <noisysocks@git.wordpress.org> Co-authored-by: ramonjd <ramonopoly@git.wordpress.org>
Hey @amitraj2203 👋 Would you be able to help write a dev note for this for the 6.7 release? We are planning to have this as part of a larger Miscellaneous Editor Updates note. We are hoping to get all drafts in by October 13th to leave some time for reviews before the RC1. All Dev Notes get tracked in #65784 so feel free to leave a note there or ping me directly :) Please let us know if you can assist with that. Thanks in advance :) |
Hi @fabiankaegy, sorry for the delayed response. I have updated this PR's description with the dev note. Please take a look at it and let me know if any changes need to be made. Thanks :) |
What?
Closes: #62259
Why?
This PR addresses the need for the Post Date block to display the date in a relative format.
How?
This PR adds a
Time Ago
human-diff
date format option to display relative times (e.g., "2 days ago"), enhancing the flexibility of date formatting in the editor.Testing Instructions
CHOOSE A FORMAT
Screenshots or screencast
✍️ Dev note: New 'human-diff' Date Format Option
A new date format option has been introduced for the
Post Date
andComment Date
blocks, allowing users to display dates in a human-readable, relative format.The
human-diff
format presents dates in a more intuitive way, such as12 hours ago
,2 days ago
, ora month ago
. This enhancement provides a more user-friendly way to display date information, which can improve readability and engagement for readers.To use this new format, users can select the option that displays an example of the relative time format (e.g., "2 years ago") from the
Choose a format
dropdown in the block settings panel for both the Post Date and Comment Date blocks. The feature utilizes WordPress's built-inhuman_time_diff()
function to calculate and display the relative time difference.To access this option:
Choose a format
option.