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

Add humanTimeDiff to @wordpress/date #41598

Closed
wants to merge 5 commits into from

Conversation

opr
Copy link
Contributor

@opr opr commented Jun 8, 2022

What?

Adds a humanTimeDiff function to @wordpress/date along with some tests.

Why?

To allow the generation of a human-readable difference between timestamps that is available in Gutenberg. Also to fix #14486

How?

Using moment's from utility we can generate the differences in their human readable format. This uses the locale supplied to moment to generate the strings.

Testing Instructions

  1. Please run the unit tests (npm run test) and ensure they pass.

Copy link
Member

@vcanales vcanales left a comment

Choose a reason for hiding this comment

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

This looks like something worth exposing through @wordpress/date. Thanks for including tests.

Comment on lines 572 to 575
// Normalize inputs to a moment object, defaults to current time.
from = momentLib( from );
to = momentLib( to );
return from.from( to, ! includeAffix );
Copy link
Member

Choose a reason for hiding this comment

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

I think it's worth it, in order to avoid mutations and help readability, to define to and from as new constants with a distinct name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the review. I agree!

I chose momentTo and momentFrom, do you have any better suggestions?

@vcanales vcanales added the [Type] Enhancement A suggestion for improvement. label Jul 15, 2022
@opr opr requested a review from vcanales July 18, 2022 09:45
@opr opr closed this May 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Technical Feedback Needs testing from a developer perspective. [Package] Date /packages/date [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Date: Add function to get relative time
4 participants