News for hackers. Stuff that matters.
Re:Day.js Fast 2kB alternative to Moment.js with the same mo... by TekMol on Sunday October 09, 2022 @03:10AM (#33138841)
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 mo... by epgui on Sunday October 09, 2022 @03:18AM (#33138865)
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 mo... by TekMol on Sunday October 09, 2022 @03:39AM (#33138936)
This was the reply I was trying to prevent by saying "minimal code example".

I'm not interested in long theoretical articles. But I would look at 3 lines of code.

Re:Day.js Fast 2kB alternative to Moment.js with the same mo... by krainboltgreene on Sunday October 09, 2022 @03:58AM (#33138986)
You wouldn't. It's not a trade anyone is asking.
Re:Day.js Fast 2kB alternative to Moment.js with the same mo... by 0xCAP on Sunday October 09, 2022 @03:59AM (#33138987)
This is only you having super basic date needs, not Day.js being overkill in general.
Re:Day.js Fast 2kB alternative to Moment.js with the same mo... by TekMol on Sunday October 09, 2022 @04:42AM (#33139157)
Any system, no matter how complex, can be composed of smaller units that only have super basic needs.
Re:Day.js Fast 2kB alternative to Moment.js with the same mo... by 411111111111111 on Sunday October 09, 2022 @06:24AM (#33139666)
*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.

Re:Day.js Fast 2kB alternative to Moment.js with the same mo... by 9wzYQbTYsAIc on Sunday October 09, 2022 @04:01AM (#33138994)
> I'm not interested in long theoretical articles

Those articles are more empirical in nature than theoretical.

> This logs that an image with a given id was updated

As a thought exercise, imagine that your log trail needed to be created in a distributed system, spanning multiple machine time zones, or that you needed to build a report that is read from browsers in multiple time zones that differ from multiple differing written time zones, and you need to account for human readable things like knowing what day of the week it is and what some given locale calls that day.

If you are doing the equivalent of printf debugging with your times, maybe you likely don’t need a time library.

If you are using time as a central part of a distributed algorithm, web content, or a business workflow, then you may likely need a time library.

Re:Day.js Fast 2kB alternative to Moment.js with the same mo... by TekMol on Sunday October 09, 2022 @04:44AM (#33139168)
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".

Re:Day.js Fast 2kB alternative to Moment.js with the same mo... by 9wzYQbTYsAIc on Sunday October 09, 2022 @05:37AM (#33139412)
More power to you if you have the budget to spend time writing code that someone else has already written.
Re:Day.js Fast 2kB alternative to Moment.js with the same mo... by maigret on Sunday October 09, 2022 @05:24AM (#33139355)
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.
Re:Day.js Fast 2kB alternative to Moment.js with the same mo... by 9wzYQbTYsAIc on Sunday October 09, 2022 @05:43AM (#33139449)
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 mo... by laundermaf on Sunday October 09, 2022 @04:02AM (#33138998)
I think you’re missing the point entirely. If Date has a method that does what you need, by all means use it directly.

Libraries come in handy when doing things that aren’t one liners.

A colleague thought it was super easy to change that exact ISO string to use the local timezone instead of UTC, against my advice. Guess what. The minus sign broke it and he would have never known because most customers are in the US, then they travel to Singapore and your product is worthless. By the time you hear about it, you lost the customer’s money and time therefore you lost the customer.

Moment and Luxon are too heavy, I agree, but date-fns isn’t.

Re:Day.js Fast 2kB alternative to Moment.js with the same mo... by foota on Sunday October 09, 2022 @04:44AM (#33139169)
Moment and friends shine when you need to display and interact with dates from a human perspective. Calendars, scheduled events, etc., all are hard to do without something like moment.
Re:Day.js Fast 2kB alternative to Moment.js with the same mo... by extheat on Sunday October 09, 2022 @03:27AM (#33138901)
I only see this being an issue storing times as strings. Why not store them as integers (like a Unix timestamp) or at least some standardized string format? The only reasonable use case I can think of where you absolutely need all this complexity is if you're rendering a calendar or something similar.
Re:Day.js Fast 2kB alternative to Moment.js with the same mo... by 9wzYQbTYsAIc on Sunday October 09, 2022 @03:45AM (#33138958)
There are countless, profitable business use cases for accurate time tracking.
Re:Day.js Fast 2kB alternative to Moment.js with the same mo... by ohbtvz on Sunday October 09, 2022 @08:41AM (#33140463)

    User: set an alarm in eight hours.
It's 10PM right now. At what time should the alarm be set? 6AM? Woops, tomorrow is the switch to DST! What now?

    User: remind me to brush my teeth on November 21st at 8AM.
Okay, will do! Wait, you took a plane on November 2nd and are now on the other side of the world? Should I remind you at 8AM or 5PM?

    User: please note my doctor's appointment next week at 10AM.
Sure thing bub! Wait, but you live in Morocco in 2019? And the government just announced that reverse DST will be in effect for the month of Ramadan?! WTF do I do now?

---

tl;dr It's not just an issue of storage.

Re:Day.js Fast 2kB alternative to Moment.js with the same mo... by jt2190 on Sunday October 09, 2022 @11:49AM (#33142340)
> What now?

I mean, there is no way to write code to “handle” this that isn’t just guessing on the part of the programmer. The correct thing to do is to prompt the user for verification or further information.

> There are requirements that we, as humans, will intuitively find the right interpretation for…

Interpretation is subject to error. (Yes humans have immensely more context to work with than computer programs, but just because we we’re better guessers doesn’t mean we’re not still guessing.)

Re:Day.js Fast 2kB alternative to Moment.js with the same mo... by maigret on Sunday October 09, 2022 @05:27AM (#33139371)
You can still add a library once it’s really needed and an area is proved to cause bugs. Most of the times though, developers will add them upfront “just in case”, making the bundles always heavier and thus harming the user experience with a slower UI.
Re:Day.js Fast 2kB alternative to Moment.js with the same mo... by epgui on Sunday October 09, 2022 @01:02PM (#33142999)
I’d argue that we already know how time works, so the proof exists up front and there is no “just in case”.

You could make an argument that there are more important things to fix, but then you’d be deciding consciously that it was okay to ship software known to be incorrect.

Re:Day.js Fast 2kB alternative to Moment.js with the same mo... by jwalton on Sunday October 09, 2022 @09:07AM (#33140629)
I posted about this elsewhere in the comments, but my experience with day.js is that if you're concerned with these kinds of corner cases, maybe day.js isn't the library for you.[1][2]

[1]: https://github.com/iamkun/dayjs/issues/1816

[2]: https://github.com/iamkun/dayjs/issues/1817

Re:Day.js Fast 2kB alternative to Moment.js with the same mo... by kristopolous on Sunday October 09, 2022 @03:25AM (#33138896)
I've always found moment to just present the same problems you would otherwise have with a few new ones tacked on stated in a different and more complicated way but with a pitch site and artwork.

The js date is a bit primitive and moment looks easier but in practice it's actually a convoluted clunky type system that hides important nuance behind impressively bad defaults

I used to get immediate hostility and belittling insults when I stated this about 10 years ago. I think people have finally come around. Let's see how the replies go

Re:Day.js Fast 2kB alternative to Moment.js with the same mo... by robertlagrant on Sunday October 09, 2022 @04:11AM (#33139036)
Who is "some kid"?
Re:Day.js Fast 2kB alternative to Moment.js with the same mo... by kristopolous on Sunday October 09, 2022 @04:22AM (#33139084)
Intentionally unspecified. This isn't a personal attack but instead a systemic and cultural critique

It's been like this for decades. Emotional salience sells software better than hard practicality to just about everyone. Then people rationalize their irrational choices then the timeline slips and the product sucks.

You can just sit and watch it play out like someone studying monkeys. It's remarkably predicable.

Re:Day.js Fast 2kB alternative to Moment.js with the same mo... by 9wzYQbTYsAIc on Sunday October 09, 2022 @04:33AM (#33139127)
As important as the relatively low file size is for the utility of this library, the API compatibility with Moment is perhaps the magnum opus.
Re:Day.js Fast 2kB alternative to Moment.js with the same mo... by kristopolous on Sunday October 09, 2022 @04:47AM (#33139178)
Absolutely. Great job. No question. Everyone should build things and follow their heart. Full stop.

This wasn't anything about the posted software. It was a reply to a comment.

Re:Day.js Fast 2kB alternative to Moment.js with the same mo... by 9wzYQbTYsAIc on Sunday October 09, 2022 @06:26AM (#33139686)
For sure.

Formal peer-review does trump download count, nonetheless.

And I’m all for professional licensure, continuing education programs, and formal, public reviews of the software engineering behind the open source libraries that comprise global infrastructure.

Your main point wasn’t missed.

Re:Day.js Fast 2kB alternative to Moment.js with the same mo... by robertlagrant on Sunday October 09, 2022 @06:35AM (#33139731)
How accurate can your critique be if you're so inaccurate in your metaphor for the library authors?
Re:Day.js Fast 2kB alternative to Moment.js with the same mo... by kristopolous on Sunday October 09, 2022 @01:53PM (#33143598)
I'm not a primatologist.

Tell me if you've ever had this experience.

You see something that looks like it's pretty popular. You try it. You find it has nothing but problems. After much research you then find out that other people don't have the level of sophisticated asks for the product and they are doing less complicated and less critical things.

It's the disconnect between the hype and the reality that really rubs me the wrong way. I've personally lost so much time on inappropriate tools.

Again I'm not here to insult anybody specifically or to speak poorly upon any specific product. I know how many people read these comments and I don't want to cast shade on anybody's hard work. I just wish there was more authenticity to the fit and purpose of things.

I know a lot of this depends on the users. I speak as somebody who has very popular projects and very not so popular projects. The popular ones are hyped (but sarcastically) and the ones that I worked very hard on to be extremely technical about do quite poorly.

To make things super current I haven't working for about a month on an article and I have been making sure it is extremely accurate and I know that that will probably hurt me because the liberties which inherently contain inaccuracy are simply more entertaining

This is a shared experience except for a select few. This carries is over to other things. Inaccurate pop science is read much more widely then the direct research material. There's something more emotionally approachable through this tactic. It just hurts productivity and it's a shame

Re:Day.js Fast 2kB alternative to Moment.js with the same mo... by 9wzYQbTYsAIc on Sunday October 09, 2022 @02:19PM (#33143839)
> I think the kid who wrote the library is just better at drawing cartoon characters

Quoting your writing that is probably rubbing others the wrong way, as it certainly reads easily as being specific to “these” solutions, as you put it.

You might avoid triggering people’s negative emotions by sticking to your main point and avoiding the marginalizing.

Re:Day.js Fast 2kB alternative to Moment.js with the same mo... by robertlagrant on Monday October 10, 2022 @04:54AM (#33149252)
> I just wish there was more authenticity to the fit and purpose of things.

This is so vague. Can you say how you're relating this to dayjs? How is its purpose inauthentic?

Re:Day.js Fast 2kB alternative to Moment.js with the same mo... by 9wzYQbTYsAIc on Sunday October 09, 2022 @04:23AM (#33139087)
Must be a euphemism for “300 contributors on a js.org supported GitHub project”.
Re:Day.js Fast 2kB alternative to Moment.js with the same mo... by kristopolous on Sunday October 09, 2022 @11:41AM (#33142269)
Immediate hostility and belittling attacks strike again.

Thanks for being an unproductive asshole

Better luck in the 2030s I guess

Re:Day.js Fast 2kB alternative to Moment.js with the same mo... by 9wzYQbTYsAIc on Sunday October 09, 2022 @01:54PM (#33143613)
You are succumbing to the fundamental attribution error.

You described your comment being an attack on modern development culture, as your use of euphemism, you chose the insultingly denotative word “kid” to attack the project.

Cool attitude, too?

Re:Day.js Fast 2kB alternative to Moment.js with the same mo... by kristopolous on Monday October 10, 2022 @10:06PM (#33158664)
No I was not.

You're being sloppy imprecise and presumptive once again. I'm noticing a pattern here. Let's see if it comes in threes.

And in case you're wondering, you're the one who set the rules of this engagement, I'm only playing by them.

We can be adults any time you want.

Re:Day.js Fast 2kB alternative to Moment.js with the same mo... by robertlagrant on Monday October 10, 2022 @04:53AM (#33149249)
> Immediate hostility and belittling attacks strike again.

Nothing about that comment was belittling or hostile. It was a bit snarky, but with very good reason, and did not name its target.

Re:Day.js Fast 2kB alternative to Moment.js with the same mo... by matthewmacleod on Sunday October 09, 2022 @04:21AM (#33139079)
Hopefully the replies are the same - this is a dismissive and ill-informed view that you’ve taken as a result of your own ignorance and gatekeeping.
Re:Day.js Fast 2kB alternative to Moment.js with the same mo... by forty on Sunday October 09, 2022 @03:46AM (#33138963)
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.

Re:Day.js Fast 2kB alternative to Moment.js with the same mo... by TekMol on Sunday October 09, 2022 @03:50AM (#33138970)
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.

Re:Day.js Fast 2kB alternative to Moment.js with the same mo... by 9wzYQbTYsAIc on Sunday October 09, 2022 @04:05AM (#33139015)
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.

Re:Day.js Fast 2kB alternative to Moment.js with the same mo... by forty on Sunday October 09, 2022 @06:01AM (#33139535)
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 mo... by 9wzYQbTYsAIc on Sunday October 09, 2022 @06:10AM (#33139575)
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 mo... by ponyous on Sunday October 09, 2022 @08:31AM (#33140397)
Why can’t you use Date.getFullYear with setFullYear?
Re:Day.js Fast 2kB alternative to Moment.js with the same mo... by forty on Sunday October 09, 2022 @05:56AM (#33139511)
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 mo... by throwaway0x7E6 on Sunday October 09, 2022 @05:33AM (#33139394)
>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

Re:Day.js Fast 2kB alternative to Moment.js with the same mo... by forty on Sunday October 09, 2022 @05:58AM (#33139520)
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 mo... by inopinatus on Sunday October 09, 2022 @07:20AM (#33139978)
And they would be guilty of misleading the consumer when doing so, and possibly accounting fraud as well because neither GAAP nor IFRS recognise such a calendar; the closest available is the 4-4-5 standard.

This is why we don’t let engineers write contracts. Many seem to think that law is a programming language in which they can redefine reality. It ain’t.

Re:Day.js Fast 2kB alternative to Moment.js with the same mo... by M4v3R on Sunday October 09, 2022 @06:35AM (#33139730)
Can you write a one liner to give me the timestamp for start or end of current week, or month? How about a text representation of a difference between two dates? Relative date string (eg. “2 weeks ago”)? Date comparison between two dates that are in different time zones? Does your date calculations take leap hours and leap seconds into account? Date libraries make all these and many more operations a breeze, while rolling these on your own can be tricky, error prone and you’ll be just wasting your time.
Re:Day.js Fast 2kB alternative to Moment.js with the same mo... by mgkimsal on Sunday October 09, 2022 @08:59AM (#33140567)
> Can you write a one liner to give me the timestamp for start or end of current week, or month?

And... it's a multi tenant system, where some organizations use Sunday as the start of a week, and some use Monday. And they all want to be able to switch.

Re:Day.js Fast 2kB alternative to Moment.js with the same mo... by Macha on Sunday October 09, 2022 @07:44AM (#33140129)
Users in timezone A need to schedule events many months in the future in timezone B, and display them in a report in timezone C.

In addition, should the legal authority in timezone B change their DST rules in the meantime, the local time of the event as observed in timezone B should still be what the user initially selected, which is not the same in UTC as it was at creation time

Re:Day.js Fast 2kB alternative to Moment.js with the same mo... by tasqyn on Sunday October 09, 2022 @08:06AM (#33140256)
different countries use different date format and also how do you manage languages?