You should clone theDate
into checkQuarter
as Moments are mutable.
https://momentjs.com/docs/#/manipulating/
this means that var checkquarter = theDate.add(30, 'minutes');
is changing theDate
and checkQuarter
is just another reference to theDate
.
Have a look at the console when you run the following :
var theDate = moment("1995-12-25 14:00");
console.log(theDate.toString());
var newDate = theDate.add(10, "minutes");
console.log(theDate.toString());
console.log(newDate.toString());
var anotherDate = moment(theDate);
anotherDate.add(10, "minutes");
console.log(anotherDate.toString());
console.log(theDate.toString());
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…