Calculate the sum of the time for column

Total duration time
Anna 31800:00:50 62700
Bob 318 00:00:27 62703
Mike 318 00:00:36 88455233284
var totalDurationTime = document.getElementsByClassName("total_duration_time")[0],
    durationTimes = document.getElementsByClassName("duration_time"),
    total = {
        hours: 0,
        minutes: 0,
        seconds: 0
    };

function zeroPad (num) {
    var str = num.toString();
    
    if (str.length < 2) {
        str = "0" + str;
    }
    
    return str;
}

Array.prototype.forEach.call(durationTimes, function (time) {
    var parts = time.textContent.split(":"),
        temp;
    
    temp = (+parts[2] + total.seconds);
    total.seconds = temp % 60;    
    temp = (+parts[1] + total.minutes) + (temp - total.seconds) / 60;
    total.minutes = temp % 60;    
    total.hours = (+parts[0] + total.hours) + (temp - total.minutes) / 60;
});

totalDurationTime.textContent = zeroPad(total.hours) + ":" + zeroPad(total.minutes) + ":" + zeroPad(total.seconds);

No comments:

The 6 New Rules of Communicating

The era of teleprompters and talking points has come to an end ͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­...

Contact Form

Name

Email *

Message *