DEV Community

Shameel Uddin
Shameel Uddin

Posted on

Moment.js Is Now Legacy Project | Alternatives?

If your project deals with complex date and time then you probably have been use to of moment.js. Be aware, Moment.js has become a legacy project. You can check the project status here,

We now generally consider Moment to be a legacy project in maintenance mode.
Enter fullscreen mode Exit fullscreen mode

Furthermore,

 It is not dead, but it is indeed done.
Enter fullscreen mode Exit fullscreen mode

So, what's next?

Go for these:

dayjs

Fast 2kB alternative to Moment.js with the same modern API. I myself have used this for more than a year and found it really cool, easy and super helpful.

Get started here:
https://day.js.org/docs/en/installation/installation

date-fns

date-fns provides the most comprehensive, yet simple and consistent toolset for manipulating JavaScript dates in a browser & Node.js.

Get started here:
https://date-fns.org/docs/Getting-Started

luxon

A powerful, modern, and friendly wrapper for JavaScript dates and times.

Get started here:
https://moment.github.io/luxon/#/?id=luxon

Happy coding! πŸš€πŸ‘¨β€πŸ’»πŸŒ

Follow me for more such content:
LinkedIn: https://www.linkedin.com/in/shameeluddin/
Github: https://github.com/Shameel123

Oldest comments (34)

Collapse
 
shameel profile image
Shameel Uddin

Add any other cool alternatives if you know of any. =)

Collapse
 
wraith profile image
Jake Lundberg • Edited

TC39 is working on a new API called Temporal that looks very promising. It’s in Stage 3 so it’s worth having a look!

Collapse
 
dsaga profile image
Dusan Petkovic

Interesting, it kind of makes sense to have a global namespace for managing datetime

Collapse
 
lionelrowe profile image
lionel-rowe

Just in the last couple of weeks a major roadblock to browsers shipping Temporal implementations has been resolved β€” namely github.com/tc39/proposal-temporal/... (which was opened back in Mar 2021). There still aren't any fully compliant implementations that are ready to ship, though.

Collapse
 
icolomina profile image
Nacho Colomina Torregrosa

We're currently working with date-fns and it works like a charm. I recommed it

Collapse
 
polaroidkidd profile image
Daniel Einars

We replaced it with dayjs. The API is similar enough. If ended up not being that much work

Collapse
 
razi91 profile image
jkonieczny

Use Luxon while waiting for Temporal. Or write your own wrapper for Intl, is you need performance (trust me, manually written wrapper on Intl can be 20 times faster than string formats in any of these libraries)

Collapse
 
shameel profile image
Shameel Uddin

Legacy has a certain meaning in our line of work and yes it changes a lot of things :-)

Collapse
 
wakywayne profile image
wakywayne

@shameel Can you elaborate?

Collapse
 
tech-foutraque profile image
tech foutraque

I use date-fns as a replacement, and it does the job.
The documentation is sometimes a bit tight on certain use cases.

Collapse
 
nikunjbhatt profile image
Nikunj Bhatt

This is what I don't like about software development. I am not talking about Moment.js. It's about the developers who think that a software is dead because no update is made. And since how much time? It depends on some random developers who think so!

There are objectives for developing a software. And when they are achieved, the software is declared dead!? There are many software which developers stop using for no logical reason, even when the developers haven't declared them dead, unmaintained, obsolete. But the wheel is reinvented, completely opposite of the reason behind making the software - that is, developers don't have to write the same code from scratch for every project they work on!

If a software has achieved its objectives then it is perfect for use. It is tried and tested. A lot of documentation, questions and answeres, solutions are available. Developers know its APIs. There are readymade code samples to copy-paste. Jumping to another software may require to create new code, new documentation, advertisement; and most importantly - a lot of time is wasted in developing, testing, debugging, learning, giving answers to questions.

I am seeing that new features are added in many software just because developers don't consider them dead. After a point, the newly added features are so odd that not even 0.00...001% developers use those features. Only their size increase. They become bloatware.

Many times it looks like the developers of the new software just want attention; it may be to be popular, add an achievement to their job profile, have money-making ideas, or any other reason.

Collapse
 
shinigami92 profile image
Shinigami

This is partially true, but not for moment.js
moment.js was developed into a wrong direction, like it has not immutability and also not good support for diverse calendar systems
It has also some other bugs

Luxon was a fresh start and addressed some of the design flaws that moment.js did

Also moment.js became to big and also stale in terms of modern js support
If you have a project that is meant to be only existing for the next 5 years and already runs since 2+ years, stay with moment.js
If you have a project that will be released in the next time, go with something else then moment.js

Collapse
 
frp profile image
frp

On one of the projects I touched recently, Moment.js was the single biggest contributor to the JS bundle bloat. That's because moment.js rolls its own localisation instead of using the Intl API. For this reason alone, it's not a good library to use on the frontend.

Collapse
 
anubarak profile image
Robin Schambach • Edited

I would suggest you to treeshake the languages you don't need.
After doing so it is much smaller

There is a Plugin

new MomentLocalesPlugin({
    localesToKeep: ['de-DE'],
}),
Enter fullscreen mode Exit fullscreen mode
Collapse
 
christianpaez profile image
Christian Paez

I agree, I still use moment cause honestly it works, nowadays if something is not updated every couple months then it's "legacy"

Collapse
 
dannyengelman profile image
Danny Engelman • Edited