Reputation: 1274
I have a problem about moment.duration giving me a NAN value. In the documentation it says that it's okay to give it a string value moment.duration(String)
. I'm fairly lost here and getting nowhere.
vm.generatedData value
vm.generatedData = [{ overtime: 'Mon Nov 27 2017 01:00:00 GMT+0800 (+08)' }, { overtime: 'Wed Nov 29 2017 02:25:00 GMT+0800 (+08)' }];
controller
function getTotalOvertime() {
var total = 0;
console.log(vm.generatedData);
for (var x = 0; x < vm.generatedData.length; x++) {
var format = moment(vm.generatedData[x].overtime).format('HH:mm:ss');
vm.add += moment.duration(format);
console.log(vm.add); // NAN VALUE
var d = moment.duration(vm.add);
vm.totalOT = parseInt(d.asHours()) + ':' + d.minutes();
}
}
Upvotes: 0
Views: 354
Reputation: 1351
Your issue isn't with moment, it is that vm.add
doesn't have a value yet. Set vm.add = 0
along with total
, and you should see it work again.
You can check this out by logging moment.duration(format)
, and see that it returns a number.
Upvotes: 1