• Deebster@programming.dev
    link
    fedilink
    arrow-up
    18
    ·
    7 days ago

    I’ll be very happy to not have to use Date any more. Pop quiz, what’s in whatnum?

    const vday = new Date('14 February 2025');
    const whatnum = vday.getDay() - vday.getMonth();
    

    Err, it’s 5… Ha, amazing; that’s not even the gotcha I meant to demonstrate. getDay returns the day of the week, the day of the month is returned from getDate.

    Take two:

    const vday = new Date('14 February 2025');
    const whatnum = vday.getDate() - vday.getMonth();
    

    So this is 14 - 2 = 12, right? Nope! The day (from getDate) is 1-based whereas month is 0-based, so 14 - 1 = 13.

    • SaintWacko@slrpnk.net
      link
      fedilink
      English
      arrow-up
      6
      ·
      7 days ago

      Man, I can’t remember the last time I used Date. I either use moment or… the other big one. I think it’s just a three letter name?

    • rg_
      link
      fedilink
      arrow-up
      4
      ·
      7 days ago

      I’m quite lucky because I only had to solve an issue with JavaScript dates once, but what a nightmare it was… I had to understand how timezones worked, that was not fun!

  • dracs@programming.dev
    link
    fedilink
    English
    arrow-up
    3
    ·
    7 days ago

    Thank god. I’ve been regularly checking the Github page waiting for it to finally land in browsers. Can hopefully start using the pollyfill for it soon.