I've encountered a challenge where I need to calculate the total time duration from an array that contains time durations like
['00:30', '01:30', '03:00', '04:30']
. The code snippet I'm using for this task seems to be producing unexpected results such as 00000.5010.503040.5:0
. Has anyone faced a similar issue when trying to sum up time durations before?
function calc_tot_dur() {
var total_durs = ['00:30', '01:30', '03:00', '04:30'];
var dim = '00:00';
jQuery.each(total_durs, function(index, value) {
//console.log(value);
dim_split = dim.split(":");
hs = dim_split[0];
ms = dim_split[1];
value_split = value.split(":");
v_hs = value_split[0];
v_ms = value_split[1];
console.log(hs + v_hs);
dim = (hs + v_hs) + ':' + (ms + v_ms);
// console.log(dim);
ms_hs = (ms + v_ms) / 60;
if (ms_hs > 0) {
dim = (hs + v_hs + ms_hs) + ':' + (00);
} else {
dim = (hs + v_hs) + ':' + (ms + v_ms);
}
});
alert(dim);
}