-
Notifications
You must be signed in to change notification settings - Fork 4.8k
@wordpress/date: Moving away from moment and the role of the package #43533
Description
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:
@wordpress/dateas the centralized datetime-utils library of Gutenberg. All other packages requiring datetime-related utilities would import@wordpress/date- (as suggested by @noisysocks in DateTimePicker: Replace react-dates and moment with useLilius and date-fns #43005 (comment))
@wordpress/dateas 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_datein 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))