Live data from Hacker News

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

day.js.org

41–50 of 141 posts

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

#41
post #34
post #29

Earlier quoted context omitted.

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 ar…

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 a few lines of code. Here is an example of some code I recently wrote: logEvent { 'date': new Date().toISOString(), 'event': 'image_updated', 'value': image['id'], } This logs that an image with a given id was updated. Why would I trade in my single date line for 423 files…

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 modern API

#42
post #34
post #29

Earlier quoted context omitted.

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 ar…

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 a few lines of code. Here is an example of some code I recently wrote: logEvent { 'date': new Date().toISOString(), 'event': 'image_updated', 'value': image['id'], } This logs that an image with a given id was updated. Why would I trade in my single date line for 423 files…

> 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 modern API

#43
post #34
post #29

Earlier quoted context omitted.

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 ar…

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 a few lines of code. Here is an example of some code I recently wrote: logEvent { 'date': new Date().toISOString(), 'event': 'image_updated', 'value': image['id'], } This logs that an image with a given id was updated. Why would I trade in my single date line for 423 files…

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 modern API

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

Why do you reckon the average webpage size is closer to 1MB? Could it be perhaps because people do not obsess with xKB?

It’s just 140kb extra, don’t worry about it. Repeat 5 times.

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

#45
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.

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 modern API

#46
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…

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 approach all of these "better than what the…

Who is "some kid"?

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

#47
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…

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 approach all of these "better than what the…

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 modern API

#48

Earlier quoted context omitted.

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 approach all of these "better than what the…

Who is "some kid"?

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 modern API

#49

Earlier quoted context omitted.

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 approach all of these "better than what the…

Who is "some kid"?

Must be a euphemism for “300 contributors on a js.org supported GitHub project”.
Post reply on HN