JSFiddle - React, Tailwind, and code Playground
by ainop
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.3/moment.min.js"></script>
<form id="form">
<textarea cols="80" rows="5" id="input">
1435323283 [WS-8949] js fixup
1435313060 [WS-8949] Progress widget fixup fixup
</textarea><br/>
<input type="submit"/><br/>
<textarea cols="80" rows="5" id="result"></textarea>
</form>
JavaScript
var form = document.getElementById('form');
var input = document.getElementById('input');
var result = document.getElementById('result');
form.onsubmit = function (e) {
e.preventDefault();
var rows = _.chain(input.value.split(/\r|\n/gi))
.map(function (row) {
var match = row.match(/^(\d+)\s+(.*)/);
return match ? match.slice(1) : null;
})
.filter()
.value();
_.each(rows, function (row, i, rows) {
if (rows[i + 1]) {
var ms = moment(rows[i][0] * 1000).diff(rows[i + 1][0] * 1000);
var diff = moment.utc(ms).format("HH:mm:ss.SSS");
}
row[0] = moment(row[0]*1000).format();
row.splice(1, 0, diff);
});
result.value = _.map(rows, function (row) {
return row.join('\t');
}).join('\n');
};