• railsdev@programming.dev
    link
    fedilink
    arrow-up
    2
    ·
    edit-2
    8 months ago

    I agree here. The convenience it may offer to developers who try it might be nice but the trade off is random craziness. I support not supporting features that are unintuitive. In this case that means not allowing someone to add “one month” to a date.

    • ricecake@sh.itjust.works
      link
      fedilink
      arrow-up
      1
      ·
      8 months ago

      So, the flip side to that is that sometimes you need to add one month to a date, because that sometimes how human systems are written.
      By not providing a function that does that, you’re just pushing the confusion down to the developer, who is more likely to make terrible errors in the process, get frustrated, or use one of N different competing libraries, each of which chose a different answer.

      Omitting functionality that can behave unintuitively in certain circumstances means leaving out a lot of functionality that people need.

      Like, “decimal numbers” go pathological in certain cases. So do Unicode characters. Don’t even bother thinking about connecting to the network.

      • railsdev@programming.dev
        link
        fedilink
        arrow-up
        2
        arrow-down
        1
        ·
        edit-2
        8 months ago

        In Ruby (with ActiveSupport) I would do something like 4.days.from_now or 30.days.from_now.

        If I really needed “one month from now” on some specific day of the month that not every month has I’d do:

        def 31st_of_next_month
          next_month = (Time.current.end_of_month + 1.day).beginning_of_month
          day = next_month + 31.days
          return day if day.month == next_month
        
          # last day of month if no 31st
          next_month.end_of_month.beginning_of_day
        end
        

        Disclaimer: I’m laying in bed typing this on mobile. The code probably sucks but I’m writing for illustrative purposes.

    • ☆ Yσɠƚԋσʂ ☆@lemmy.mlOP
      link
      fedilink
      arrow-up
      3
      arrow-down
      8
      ·
      8 months ago

      Exactly, it’s better to not have these sorts of “conveniences” than to create weird pitfalls. I find a lot of crazy Js behaviors are ultimately a result of Js trying to be accommodating of inputs that should just be straight up rejected.