使用时刻添加两个持续时间时出错

Error while adding two time duration using moment

我正在尝试添加两个持续时间,如下所示,我只得到第一个赋值,而不是上面的总和值。 哪里不对请大家帮忙?

public rasiBalance:'';
public sunRise:'';
// storing the values for the above from some other function
 public getDuration(){
    console.log('Rasi Balance:'+this.rasiBalance); //Output : 0.31
    console.log('Sun Rise:'+this.sunRise); // Output: 6.38
let Lagnam1 = '00:00';
Lagnam1 = moment(this.rasiBalance, 'HH:mm').add(this.sunRise, 'HH:mm').format('HH:mm');
console.log('Lagnam 1:'+Lagnam1);

  }

答案在这里

var moment = require('moment');

let rasiBalance = 0.31;
let sunRise = 6.38;

function getDuration() {
    console.log('Rasi Balance : ' + rasiBalance);
    console.log('Sun Rise : ' + sunRise);
    console.log ("Time addition output :", addTimes(rasiBalance,sunRise));
}

// To add two times
function addTimes(time1,time2){
    let convertedTime1 = convertToHoursAndMinutes(time1);
    let convertedTime2 = convertToHoursAndMinutes(time2);
    return parseFloat(moment(convertedTime1.hours + ":" + convertedTime1.minutes, "HH:mm").add(convertedTime2.hours,"h").add(convertedTime2.minutes,"m").format("HH:mm").replace(":","."));
}

// To split hours and minutes - We can even try to ignore this function 
// if time and minutes can be split easily and fed into moment method inside the addTimes function
function convertToHoursAndMinutes(valueToConvert){
    var convertedTime = {};
    convertedTime.hours = valueToConvert - parseFloat((valueToConvert % 1).toFixed(2));
    convertedTime.minutes = parseInt((valueToConvert % 1).toFixed(2).substring(2));
    return convertedTime;
}

getDuration();