moment-round
moment-round copied to clipboard
Why the rounding functions have to modify the moment object
Just curious about the reason why the moment object gets modified after calling floor, ceil or round. What if you want to get both floor and ceil of same moment. Do you have to make a deep copy of the moment object ?
Please correct me if I missed something
console.log();
var m1 = moment();
console.log(m1);
m1.floor(10, 'minutes');
console.log(m1);
console.log();
var m2 = moment();
console.log(m2);
m2.ceil(10, 'minutes');
console.log(m2);
clone the moment object first before rounding.
m1.clone().floor(..)
Moment always mutates the object - e.g. for .add() or .subtrack()