re: The 7 best JavaScript date libraries VIEW POST


What is the use case for not using the native Date functionality in js? Surely using the Date methods would be a preferred option given that it reduces the number of packages you use?


The Date object's API is not rich enough, I like to think of it as the assembler to these libraries C.
In other words, most of them use it at their core, but they add several layers of abstraction in order to help make your code more readable and easier to maintain.

Look at the example from the MomentJS section:

moment().add(7, 'days').subtract(1, 'months').year(2009).hours(0).minutes(0).seconds(0);

You can't do that with the Date object using that syntax, in fact, there are no methods to add or substract anything to its original value. The fact that there are so many libraries out there I think is literally proof that Date is not getting the job done.


So guessing from the example that it primarily helps with the readability of complex date calculations rather than the readability of a date string. I haven't had to use a package for dates in any of the projects I've worked on so genuinely interested what the decision rational is and what Date doesn't do that forces developers to create packages for that functionality.

code of conduct - report abuse