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.
Furthermore,
It is not dead, but it is indeed done.
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)
Add any other cool alternatives if you know of any. =)
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!
Interesting, it kind of makes sense to have a global namespace for managing datetime
Just in the last couple of weeks a major roadblock to browsers shipping
Temporalimplementations 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.We're currently working with date-fns and it works like a charm. I recommed it
We replaced it with dayjs. The API is similar enough. If ended up not being that much work
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)
Legacy has a certain meaning in our line of work and yes it changes a lot of things :-)
@shameel Can you elaborate?
I use date-fns as a replacement, and it does the job.
The documentation is sometimes a bit tight on certain use cases.
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.
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
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.
I would suggest you to treeshake the languages you don't need.
After doing so it is much smaller
There is a Plugin
I agree, I still use moment cause honestly it works, nowadays if something is not updated every couple months then it's "legacy"
Github: You Don't Need MomentJS