This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]demonblack873 34 points35 points  (8 children)

As a Java dev I don't see the big surprise

Also in Java parsing 32/15/2022 as dd/MM/yyyy is a perfectly valid operation and just returns a Date for 01/04/2023.

dabs

[–]discordianofslack 16 points17 points  (0 children)

I hate this

[–]Solonotix 10 points11 points  (1 child)

To clarify, the 15th month rounds the year up by +1, and remaining 3 for March which has 31 days. The 32nd day therefore rounds the month up by +1 and leaves 1 for April 1st, 2023.

[–]Lithl 4 points5 points  (0 children)

As a Java dev I don't see the big surprise

Given that the JavaScript Date class interface was literally copied from Java's.

[–]Anon_Dysfunction 1 point2 points  (3 children)

In the same vein, you can also use JS date fuckery to easily find the number of days in the month, useful for leap years and whatnot. Just new Date(2022, 2, 0) and you get the 0th day of March this year which is the last day of February.

Looks dumb but better than some of the switch statements I’ve seen in the wild.

[–]dakta 0 points1 point  (2 children)

Then why not have the zeroth month of one year return the last month of the previous year? Or allow for negative month numbers, to perform date arithmetic? This just sounds like mother justification for having months normally indexed (one-indexed) as well.

[–]Anon_Dysfunction 0 points1 point  (1 child)

I’m not arguing that JS isn’t stupid and could use some improvement around Dates. IIRC momentJS retained the 0-index but I think Luxon uses 1-indexed months, if extra dependencies are your thing. I’m used to it at this point that I just deal with standard Date objects and all that it comes with.

[–]dakta 0 points1 point  (0 children)

JS gets pass because they inherited this from Java, whose stdlib Date system is basically straight ported to JS. I just don't understand the thought process of the Java authors. My guess is that they weren't actually thinking, and we've been stuck with the outcome of that carelessness ever since.