Post AT2mu4MZW1VcOEfbO4 by janeadams@vis.social
 (DIR) More posts by janeadams@vis.social
 (DIR) Post #AT1FE19pYHiYdl5hOS by phryk@mastodon.social
       2023-02-24T22:32:05Z
       
       0 likes, 0 repeats
       
       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:
       
 (DIR) Post #AT1FE1yAX7z39sdtr6 by phryk@mastodon.social
       2023-02-24T22:32:37Z
       
       0 likes, 0 repeats
       
       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.
       
 (DIR) Post #AT1FE2bs9Vk791Dbk0 by phryk@mastodon.social
       2023-02-24T22:53:53Z
       
       0 likes, 1 repeats
       
       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… 🤦
       
 (DIR) Post #AT1FE33WUhrQWm9gq8 by john@sauropods.win
       2023-02-24T22:58:49Z
       
       0 likes, 0 repeats
       
       @phryk Javascript was deigned in a week. Cut it some slack! 😉But seriously, I actually hate it, and every time I write something semi-serious in another language I’m reminded that things can be better.Oddly, though, I don’t mind JS for short one-off animation things with canvas. Works for that.
       
 (DIR) Post #AT2PxDGgZ6npvoRl7g by phryk@mastodon.social
       2023-02-25T00:58:46Z
       
       0 likes, 0 repeats
       
       excuse me what the fuck 🤣
       
 (DIR) Post #AT2PxDscI58zpSC3FI by phryk@mastodon.social
       2023-02-25T01:03:59Z
       
       1 likes, 0 repeats
       
       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.
       
 (DIR) Post #AT2d2hhCA8WB9XnLV2 by WomanCorn@schelling.pt
       2023-02-25T15:00:35Z
       
       0 likes, 0 repeats
       
       @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?
       
 (DIR) Post #AT2eABkgub3KLuYy36 by heathborders@hachyderm.io
       2023-02-25T15:13:07Z
       
       0 likes, 0 repeats
       
       @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
       
 (DIR) Post #AT2mu4MZW1VcOEfbO4 by janeadams@vis.social
       2023-02-25T02:33:23Z
       
       0 likes, 1 repeats
       
       @phryk For curious folks, getYear() is deprecated due to the Y2K problem (who ever could have predicted?? lol) and you should use getFullYear() instead. But this reminds me of my favorite ever #javascript cartoon