21

Fuck you javascript and your bizarre Date object.
May your ass itch, and arms become too short to reach.

Spend a good hour debugging why this fucker:
(new Date).getDay();

Returns 3, when it's actually the 2nd of May.

Turns out the value returned by getDay is an integer corresponding to the day of the week.

(new Date).getDate(); it is, ಠ_ಠ

Comments
  • 5
    Try moment.js 🙄
  • 18
    I can't see a problem here. Read the fucking manual of js, don't blantly assume that something will return exactly what you want.
  • 5
    @py2js How about proper naming of functions.
    Could have called it getDayOfWeek
  • 1
    @theMaintainer if they documentef it then it is okay and RTFM. Name is I think pretty much okay
  • 1
    @Tuffbard Aye, I second this. With JS' Datetime being pretty much broken this is good at have.

    Also helps with the timezone shit
  • 3
    I don't understand why we need to blame everything on JS, this is a perfect example of PEBCAK.
    Yes it could have been named better, but you made the primitive mistake of assuming what it does without referring to docs.
    I have been there, maybe I am still here, not a place you want to be as a developer.

    And yeah, datetime in JS needs an overhaul.
  • 1
    JS is made to be as understandable as possible. You have to think it as a huge standard instead of a language developed by a single company.

    You still might not understand specific APIs with intuition, but that's why internet is full of offical and unoffical documentation.
  • 1
    @Tuffbard Bloated. date-fns is better and more modular.
  • 0
    I agree with the rant.
    • Some of the method names could be better.
    • Some of their returns start at 0, some start at 1.

    There are other issues, but I can't remember them right off.
  • 1
    Conclusion : whoever developed JS, he was not good in any language so he decided to create his own one and follows no rule and standard, helping people who wand a something "just working"
  • 0
  • 0
    @lazyDev

    It just makes no sense because someone did the APIs at first yes, but it had to be adopted by a lot of different organizations for it to be as popular as it is today.

    Maybe they all were ignorant...
  • 0
    As mush as I hate JS, moment js made working with dates less terrible.
  • 0
    @theMaintainer

    I'm a full-time JS developer and I have been developing with JS for a long while now, so I would say I know a bit about it, and yes, you're right. The Date object in JS is pretty much broken. It was copied from java.util.Date, which also had the same quirks.

    This happened in 1995, and JDK 1.0 was in beta. It launched in 1996. In 1997, JDK 1.1 came out which deprecated the vast majority of functions on java.util.Date, moving them over to java.util.Calendar. Developers fed-up with this created the Joda-Time library, which ultimately led to java.time package that's baked in to Java 8 (2014).

    In short, it took 18 years for Java to get a correctly designed date/time API built-in, but JavaScript is still stuck back in the dark ages. We do indeed have excellent libraries like Moment.js, date-fns, and js-joda. But as of now, there is nothing more than Date built-in to the language. Hopefully this will change in the near future.
  • 0
Add Comment