JSFiddle - React, Tailwind, and code Playground

by Graham Fairweather

HTML

<table id="total" border="1" width="100%">
    <tbody>
        <tr>
            <td>Total duration time</td>
            <td class="total_duration_time"></td>
        </tr>
    </tbody>
</table>
<table id="data" border="1" width="100%">
    <tbody>
        <tr>
            <td>Anna</td>
            <td>318</td><td class="duration_time">00:00:50</td>
            <td>62700</td>
        </tr>
        <tr>
            <td>Bob</td>
            <td>318</td>
            <td class="duration_time">00:00:27</td>
            <td>62703</td>
        </tr>
        <tr>
            <td>Mike</td>
            <td>318</td>
            <td class="duration_time">00:00:36</td>
            <td>88455233284</td>
        </tr>
    </tbody>
</table>

JavaScript

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);