5 ms·
Our favorite bug for newbies using moment.js: const somedate = moment(...somedate...); const oneMonthLater = somedate.add(1, 'M'); const dateToCheck = ..
by firebaze 6y ago
Our favorite bug for newbies using moment.js:
const somedate = moment(...somedate...);
const oneMonthLater = somedate.add(1, 'M');
const dateToCheck = ...; // between somedate and somedate + 1 month
if (dateToCheck.isBetween(somedate, oneMonthLater)) {
// do something
}
The puzzled looks when the tests fail. I'll miss that. Seriously.
- NanoWar 6y agoGotta love immutables after that...
- superfrank 6y agoJust to confirm that I remember Moment correctly, the code in the if statement never runs because .add mutates somedate, so somedate and oneMonthLater are the same, correct?
- balls187 6y agoYes, `somedate` is mutable.
- edgarvaldes 6y agoYes, it bit me once