9

Somehow they felt like the first day of a month isn't always n°1 (and last day might be smaller than 10)

Comments
  • 1
    Maybe something about supporting the julian to gregorian calendar transition lol
  • 6
    Ask ChatGPT for an explanation 🧐
  • 2
    @Oktokolo it seems not even ChatGPT can explain this code. You can tell it's trying, but doesn't really make sense.
  • 2
    @NodaiWTF Wow, there probably is a StackOverflow answer with 10k+ upvotes getting that right. I wonder why it fucked up this one.

    At least it didn't fall for the absurdly bad method name...
  • 9
    Holy shit this is bad. This is the very definition of throwing shit at the wall until something sticks. This is like someone slammed their face on the keyboard repeatedly until their code passed the test.
  • 1
    What probably happened is they had a formatDate method (any date) in another project copy pasted over and the dev who pasted it then just split the date param in first and last, not bothering with removing the no longer applicable lines.
  • 1
    @webketje I believe that's how it went, but still even the first day calculation is bollocks!
  • 1
    @NodaiWTF haha yeah, new Date().setDate(1). I was distracted by the fact that the calculations do make sense in isolation (in a formatDate function) but definitely not if only used for getting the first day =D
Add Comment