Live data from Hacker News

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

day.js.org

71–80 of 141 posts

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

#71
post #60
post #55

Earlier quoted context omitted.

You are trying to convince me with the popular "This is not going to work for a much more complex system". I heard it very often. I don't buy it. Any system, no matter how complex, can be composed of small, simple systems. I never ran against a "complexity wall" when writing software in a lean way and suddenly thought "Damn, those tens of thousands of lines of library code now would be the better approach".

That’s very true. A colleague recently started using the same method and is achieving bundles and dependencies orders of magnitude smaller. As a result, he has to care less about security, build times and build breaks and spends more time coding. Developers have unlearned to build basic functionality apparently, especially in the front end area.

It’s not really a question of unlearning, its more of a question of economics.

Sound software construction techniques are one thing, but convincing someone to pay you to reinvent the wheel is another.

Especially when you consider that budgets for new, bespoke brand websites can start as low as about a couple of days pay for a senior developer.

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

#72
post #38
post #37

Earlier quoted context omitted.

Any operation like adding/substracting months from a date is very messy to implement yourself. What is one month ago when you are March, 31st? We have to deal with monthly subscriptions and it's not fun.

First you have to define what you mean by "one month ago". Is it 30 days ago? Or last month? Or a certain number of milliseconds ago? No library can help you with that. You have to define what you actually want to calculate.

Absolutely. moment has a definition of that and compute it in a consistent way, which is useful. But if you want to come up with a different definition then it cannot help you indeed.

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

#73
post #37

Earlier quoted context omitted.

Any operation like adding/substracting months from a date is very messy to implement yourself. What is one month ago when you are March, 31st? We have to deal with monthly subscriptions and it's not fun.

>What is one month ago when you are March, 31st? "one month ago" is between "a few weeks ago" and "a few months ago". >We have to deal with monthly subscriptions and it's not fun. it is a lot less unfun if you define a month as N calendar days in your terms of service, like virtually everyone does

Yes, that's what we do mostly, except to track external subscriptions that actually use months (I believe the Google playstore does that but I could be mistaken with another service)

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

#74
post #13

Earlier quoted context omitted.

But how does this compare to Luxon, besides it being the preferred library of blahyawnblah?

https://terodox.tech/migrating-away-from-momentjs-part1/

Summary: day.js had DST bugs, luxon did not.

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

#75
post #38

Earlier quoted context omitted.

First you have to define what you mean by "one month ago". Is it 30 days ago? Or last month? Or a certain number of milliseconds ago? No library can help you with that. You have to define what you actually want to calculate.

At some point you will need to calculate how many leap years to account for and whether or not a leap second was introduced in between two arbitrary times. Time libraries can help you with that.

Exactly there is the same problem, to a lesser extend, when adding/subtracting years which is not trivial to do properly.

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

#76
post #75

Earlier quoted context omitted.

At some point you will need to calculate how many leap years to account for and whether or not a leap second was introduced in between two arbitrary times. Time libraries can help you with that.

Exactly there is the same problem, to a lesser extend, when adding/subtracting years which is not trivial to do properly.

Let alone determining requirements for thresholds.

This discussion reminds me of this bug report: https://bugzilla.mozilla.org/show_bug.cgi?id=1715455

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

#77
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

> I'd wager that an average webpage size is probably closer to 1MB. And the average American is heavier than they should be. Doesn't make it ideal. Always endeavour to trim the fat. This is HN, and despite the likely predominance of US big-city devs here, I'd wager that most of them like money from rural dwellers just as well as they do the money of their fellow city-slickers.

also people are gonna load Amazon and Google no matter the size.

if your shitty startup or ecommerce site takes >1s to load... not so much.

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

#78

If you are considering switching to a (different) date library, I would suggest to hold off. ECMAScript is about to introduce a native date and time API that is much better than the current Date functionality. It may also make the need for a third-party date library obsolete (as long as you do not need to parse custom date formats). - https://github.com/tc39/proposal-temporal - https://github.com/tc39/proposal-tempor…

Having read the cookbook [1], and wow that's a complex API out there. I can see that there will be a `Temporal Light` to allow us to do `now().startOf('month')` like calls. [1] https://tc39.es/proposal-temporal/docs/cookbook.html

Wouldn't this work?

    const firstInMonth = Temporal.Now.with({ day: 1 });

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

#79

> Moment.js with the same modern API Moment.js objects are mutable [0], and this library's objects are ... immutable. [0] https://momentjs.com/guides/#/lib-concepts/mutability/

The mutability in Moment.js is not really a feature though, just a massive inconvenience/source of bugs (unless you use `.clone()` all over the place).

But yeah, very important difference.

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

#80
post #53
post #41

Earlier quoted context omitted.

This is only you having super basic date needs, not Day.js being overkill in general.

Any system, no matter how complex, can be composed of smaller units that only have super basic needs.

*if all complexity has been hidden from the developer which only needs to use a decent puplic API.

I'd agree that it feels like that quiet often as a web developer, but that's only because most of our APIs are actually quiet easy to use.

The illusion usually falls away if you look at the code of that API, however.

Post reply on HN