moment-round icon indicating copy to clipboard operation
moment-round copied to clipboard

Why the rounding functions have to modify the moment object

Open xyz1hang opened this issue 7 years ago • 1 comments

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);

xyz1hang avatar Mar 28 '17 11:03 xyz1hang

clone the moment object first before rounding. m1.clone().floor(..) Moment always mutates the object - e.g. for .add() or .subtrack()

murraybauer avatar May 18 '17 02:05 murraybauer