Live data from Hacker News

Day.js – Fast 2kB alternative to Moment.js with the same modern API

day.js.org

21–30 of 141 posts

Re: Day.js – Fast 2kB alternative to Moment.js with the same modern API

#21

Earlier quoted context omitted.

The new Temporal API in JS is precisely that.

Yeah, but that’s been just a proposal for a long time. Getting new features in JS takes forever.

Considering that they tend to stay forever, I'd rather wait for them to be well designed than rushed and half-baked.

Re: Day.js – Fast 2kB alternative to Moment.js with the same modern API

#25
I'm a fan of Moment... it's served me well for most of a decade, including in some really heavy scheduling/timetable applications. The size of importing Moment is really fairly negligible for a full-scale single page app. The one drawback I find with it is the overhead for creating new Moment objects. You never want to, for instance, run through a for/next loop of SQL dates and convert each into a Moment for sorting. If you must have them as Moments, you really need to cache once and compare later. Usually in my code I even avoid writing `new Moment()` within a control structure that only needs the current day or hour, and I set up an interval to run permanently in a utility class to just cache a recent Moment every 10 seconds or so, for comparison wherever else it's needed in the code.

That's the only real issue for me with Moment and I'm not sure this lib would change that... especially if I need to extend it for various uses every time it's called, which for me would be a rather large drawback that would end up polluting lots of modules with extra lines of code for specific date comparison purposes.

Re: Day.js – Fast 2kB alternative to Moment.js with the same modern API

#26
What is the obsession with xKB? With tracking, analytics, monitoring and gazillion other scripts, I'd wager that an average webpage size is probably closer to 1MB.

Checked some of the popular sites (caching enabled)-

Amazon.com - 4.8MB

Google.com - 2.5MB

Re: Day.js – Fast 2kB alternative to Moment.js with the same modern API

#27
I never use any date library and I never had a problem with it.

I just use what the native Date() object offers.

Other devs always say "Just wait, one day it will fall on your feet".

But this has been going on for many years, in which my software has served millions of users and nothing ever fell on my feet. I think the complexity of a library like this (423 files, 1433 commits, 53004 lines of code) would have created more problems during this time. So not using one is a net positive.

Any minimal code example of what is prone to break without a date library and how this date library is supposed to prevent it?

Re: Day.js – Fast 2kB alternative to Moment.js with the same modern API

#28
post #26

What is the obsession with xKB? With tracking, analytics, monitoring and gazillion other scripts, I'd wager that an average webpage size is probably closer to 1MB. Checked some of the popular sites (caching enabled)- Amazon.com - 4.8MB Google.com - 2.5MB

When you can, you save, you’ll be faster. Also you are more willing to include more libs if they are all small, and more easily include new big ones when necessary without the soon need to rewrite your code as it became too big.

Hosting is cheaper.

Re: Day.js – Fast 2kB alternative to Moment.js with the same modern API

#29
post #27

I never use any date library and I never had a problem with it. I just use what the native Date() object offers. Other devs always say "Just wait, one day it will fall on your feet". But this has been going on for many years, in which my software has served millions of users and nothing ever fell on my feet. I think the complexity of a library like this (423 files, 1433 commits, 53004 lines of code) would have create…

Examples of essential complexity you have to worry about if you want your code to be correct, and even if you want to test/detect all issues that can/do come up:

- https://infiniteundo.com/post/25326999628/falsehoods-program...

- https://infiniteundo.com/post/25509354022/more-falsehoods-pr...

In my experience engineers will often brush these sorts of things off as “edge cases”, but really all of these complexities are just how dates and time work in the real life (I’d argue that they’re just “normal cases” to test for)… So any anomaly in software will cause real problems of varying importance for users.

Re: Day.js – Fast 2kB alternative to Moment.js with the same modern API

#30
Interesting to see the support for luxon. When moment was announced as a done project they recommend a number of alternatives; one of those was luxon. Date-fns was also in there, and given I was already using it I carried on my merry way! I'm curious what the difference between luxon and date-fns is. Npm trends are interesting

https://npmtrends.com/date-fns-vs-dayjs-vs-luxon-vs-moment

Post reply on HN