6
Angry
3y

1. Find a function: getDayDiff(d1, d2)
2. d1 and d2 are momentjs dates.
3. See that function performs complex ancient math rituals and then returns an integer
4. Try to rewrite function, return d2.diff(d1, 'days')
5. Should be OK right? Run tests
6. Whole module melts down. WTF?!

Turns out the math performed returned the difference + 1 because it included the current day which moment's diff() function does not (out of the box).

Processes that depended on this function then uses the result like this:

const diff = getDayDiff(d1, d2)
if (diff-1 == should_match) { /* more fun logic */ }

$ git checkout .
$ run-shutdown-script-because-fuck-you

Comments
  • 0
    Probably function is not named corerctly.

    There is a difference between "Number of days in the interval" (Should include both dates)

    and 'Daysto next date"
  • 1
    Off-by-one errors are awful.
Add Comment