• bleistift2@feddit.de
    link
    fedilink
    English
    arrow-up
    6
    ·
    2 months ago

    So it’s the Y2K bug, but stupider.

    As a sidenote: Did you know that the Date object in JavaScript has a getFullYear method? It just gives you the year of the date. For instance: new Date(1995, 0, 1).getFullYear() gives 1995.

    Why is it called getFullYear, you ask? Well, there’s also getYear, which only gives the last two digits of the year. For instance: new Date(1995, 0, 1).getYear() gives 95. Not as useful as you might think, but ok.

    Now what happens in the year 2000? Guess. No, really. Do guess. And then guess again, because you’re wrong. new Date(2024, 0, 1).getYear() gives …drumroll… 124, not 24. After the year 1999 the counter just keeps incrementing.

    So what’s before 1900, then? new Date(1776, 6, 4) was, of course, the year −124.

    I think it’s worth noting that JavaScript isn’t an ancient language. It was developed in December 1995. The year 2000 wasn’t too far off.