Skip to content

Date: Add function to get relative time #14486

Closed
@swissspidy

Description

@swissspidy

Is your feature request related to a problem? Please describe.

@wordpress/date, powered by Moment.js under the hood, is a neat and simple way to format dates. However, what currently is missing is a way to display relative times like human_time_diff() does in PHP.

Describe the solution you'd like

Moment.js has a function called fromNow() (docs) that allows you to display relative times like "4 years ago" or "44 seconds ago", and a similar from() function to display a moment in relation to a time other than now.

A new function similar to human_time_diff() could be added to the package that makes use of these functions.

Happy to work on a PR to add this kind of functionality.

Describe alternatives you've considered

Alternatives would be using Moment.js directly and not via @wordpress/date, or using a dedicated library like timeago.js

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions