Wanted to do some semantic date validation with #javascript "real quick".

And god damn, the Date class is a complete clusterfuck.

First of all Date is actually a datetime. MDN even gives
`const today = new Date();` as example, but that actually contains the current time, so that's useless if you want to make clean comparisons between dates.

So if you want to do clean comparisons using `<input type='date'>` you'll have to do some dumb shit a la `new Date(input.value + ' 00:00')`… :thaenkin:

But what confuses me the most is how the constructor takes months as zero-indexed integer while taking days starting from one – like if you don't do it consistently, I *highly* doubt there's any technical merit behind that bullshit.

getDate/setDate aren't for the actual date, but only for the day component.

setTime doesn't only set the time, it sets the time*stamp* – i.e. the date, too.

You really can't make this shit up… 🤦

And getMonth of course returns the month *index*, not the actual month.

I mean wow, I hate handling dates and times already, but this is literally the worst date API I have ever seen… by a wide margin.

Follow

@phryk word on the street is that they just copied the Java Date class.

I've never had to go deep on Java's Date so I don't know. Is it bad in the same ways?

@WomanCorn @phryk this is exactly like Java's Date API, but I don't know if JavaScript copied it. I thought maybe they both copied some awful C/C++ API

Sign in to participate in the conversation
Mastodon

a Schelling point for those who seek one