Page MenuHomePhabricator

Should we replace Moment.js in core with something smaller? (If yes, what?)
Open, LowPublic

Description

Moment.js is quite a large library and seems to replicate some of the logic we have in mw.msg. In Popups for example, this library is used to render a message "Edited 33 minutes ago", and this accounts for over 50% of the code. (See T137775)~ [JR: Popups no longer uses]

In MobileFrontend rather than using Moment.js we use a small library to provide information about last modified time with units. We then use this information in getLastModifiedMessage to render one of several messages.

This approach seems cheaper.

My question: should we deprecate use of moment.js in core for a more simplistic library, based on the MobileFrontend library (or some other library), that can be used with messages?

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald TranscriptSep 27 2016, 6:22 PM

Roan suggested https://github.com/jquery/globalize might be a good replacement but may equally be large.

Based on https://github.com/jquery/globalize#pick-the-modules-you-need it sounds like it might be smaller than moment, although those figures don't include the CLDR data that you need.

Jdlrobson updated the task description. (Show Details)Feb 8 2017, 7:17 PM

@Jdlrobson @Catrope “may equally be large” vs “might be smaller than moment”?!

Jdforrester-WMF renamed this task from Do we really need Moment.js in core? to Should we replace Moment.js in core with something smaller? (If yes, what?).Nov 28 2017, 7:10 PM
Jdforrester-WMF triaged this task as Low priority.

Another possible alternative hot off the news: https://github.com/xx45/dayjs – described as ”Fast 2KB date library alternative to Moment.js with the same modern API“

Another possible alternative hot off the news: https://github.com/xx45/dayjs – described as ”Fast 2KB date library alternative to Moment.js with the same modern API“

Unfortunately AFAICT that one is small and fast by not doing i18n, which is a non-starter for us.

I'm not familiar with all of moment.js abilities, but there's discussion for “internationalization” https://github.com/xx45/dayjs/issues/36

Do we use timezone localisation? This seems to be the biggest problem with moving away...

moment-timezone doesn't seem to be in use:

In the meanwhile I18n has landed in dayjs, see https://github.com/iamkun/dayjs/blob/dev/docs/en/I18n.md


For simple formatting, the JavaScript Date.toLocaleString might be sufficient (providing good browser support for its basic usage).

One question is also how strict the localized output must be, e.g., I'm relating to the en locale override in core/resources/src/moment/moment-dmy.js.

In core we have a few calls to moment() (codesearch), in MobileFrontend only two (codesearch)


Would it make sense to submit a patch replacing the moment usage in an extension such as MobileFrontend or MultimediaViewer as a starting point?