Skip to content

@wordpress/date: Moving away from moment and the role of the package #43533

@ciampo

Description

@ciampo

With PR #43005 merged, the @wordpress/components package replaced its dependency on moment with date-fns.

Since moment and moment-timezone are large dependencies, it would be great if we could migrate away from them entirely. The only package left requiring them is @wordpress/date.

I believe that, in order to decide on the next steps, we need to answer two questions:

What should the role of the @wordpress/date package be?

Potential approaches:

  1. @wordpress/date as the centralized datetime-utils library of Gutenberg. All other packages requiring datetime-related utilities would import @wordpress/date
  2. (as suggested by @noisysocks in DateTimePicker: Replace react-dates and moment with useLilius and date-fns #43005 (comment)) @wordpress/date as complimentary to a date util library (e.g. date-fns), which should only provide:
    • A store for the WordPress site's date settings including format preference and timezone.
    • A function similar to wp_date in PHP.\

As suggested by @gziolo in #43533 (comment), in order to minimize the chance of introducing breaking changes, we could keep the @wordpress/date untouched, mark it as deprecated, and potentially create a new package instead (following any of the approaches proposed above).

How should we replace moment ?

In the components package, so far moment has been partially replaced with date-fns (partially, because internationalization/formatting for each locale and timezones are still handled via @wordpress/date, which internally uses moment).

For the future, it looks like the Temporal APIs may be a great fit (as suggested by @griffbrad and @sgomes in #41385 (comment))

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Package] Date/packages/date[Type] DiscussionFor issues that are high-level and not yet ready to implement.[Type] PerformanceRelated to performance efforts

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions