79

All the stupid date functions where the days range from 1 to 31 but the months range from 0 to 11

Comments
  • 10
    the months do WHAT
  • 10
    Ah javascript, how you managed to get it soooo wrong.
  • 0
    so true
  • 2
    moment.js
  • 9
    @kamen
    Industry is drifting away from moment due to its weight. Day.js, luxon, etc are the it things now.
  • 8
    @SortOfTested I'm not a web dev so please forgive my ignorance, but are those third-party date libraries? Javascript needs third-party libraries for dates?!

    And here I thought is-odd was silly...
  • 13
    @EmberQuill
    Like many languages, it has libraries for normalization, internationalization. Java has JodaTime, dotnet has nodatime, people have ported moment to golang, rust has chrono, etc etc.
  • 2
    @SortOfTested I'm kind of surprised Moment was ported to golang. Doesn't seem to make things much easier than just using the built-in time package itself.

    I'll admit that i got used to languages with good date/time implementations and forgot that there were plenty of bad ones aside from JS.
  • 1
    @EmberQuill unfortunately, JS doesn't have everything related to dates out-of-the-box. It contains localized dates and even the rules that make them fit any locale. However, the things like relative date, timezones list and such require boilerplate code.
  • 1
    @SortOfTested Good point. Moment.js is not suitable for tree shaking, which only serves to bury it, unfortunately.
  • 0
    @EmberQuill
    It's not a problem until it is most of the time. The libraries exist for improving usability of the API, fixing any underlying bugs and making complex date handling easier.

    Most default datetime libraries are fine for working in a single time zone with no irregularities. Start adding in international and local convention, server-relative time adjustments, shifting, syncing and shit like India's 30-minute adjacent time zone and the libraries become a lot more valuable.

    Decent partial list
    https://gist.github.com/timvisee/...
  • 0
    @SortOfTested I'm pretty sure "months start at 1" is a safe assumption in most languages though. Aside from Javascript or older, now-deprecated functions in other languages.
  • 0
    @EmberQuill
    Sure, in gregorian support. The Hebrew, Hijri and Ethiopian calendars are a different story.
  • 0
    Temporal is in stage 2 draft I believe.
  • 1
    @SortOfTested Fair enough, you might be right. I haven't had the need to use something like this in quite a while (if ever), I was just pointing to the idea of a library that normalises stuff.
  • 1
    @kamen
    All good, just documenting to keep the answer fresh.
  • 0
    @kamen Moment.js is no recommended by their maintainers now so not a good choice to recommend.
  • 0
    Lolllll
  • 5
    Go watch computerphile’s (Tom Scott’s) video rant on timezones!

    That being said, I’m so happy that moment exists!
  • 0
    @Berkmann18 date-fns is usually the way to go now
Add Comment