-
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
Add humanTimeDiff
to @wordpress/date
#41598
Conversation
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.
This looks like something worth exposing through @wordpress/date
. Thanks for including tests.
packages/date/src/index.js
Outdated
// Normalize inputs to a moment object, defaults to current time. | ||
from = momentLib( from ); | ||
to = momentLib( to ); | ||
return from.from( to, ! includeAffix ); |
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.
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.
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 for the review. I agree!
I chose momentTo
and momentFrom
, do you have any better suggestions?
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
'sfrom
utility we can generate the differences in their human readable format. This uses the locale supplied tomoment
to generate the strings.Testing Instructions
npm run test
) and ensure they pass.