Fix rounding of seconds in user / library watch time stats

This commit is contained in:
JonnyWong16 2021-06-05 10:28:45 -07:00
parent b9c1dccf48
commit fcc70a9b74
No known key found for this signature in database
GPG key ID: B1F1F9807184697A

View file

@ -288,25 +288,23 @@ function isPrivateIP(ip_address) {
} }
function humanTime(seconds) { function humanTime(seconds) {
var text; var d = Math.floor(moment.duration(seconds, 'seconds').asDays());
if (seconds >= 86400) { var h = Math.floor(moment.duration((seconds % 86400), 'seconds').asHours());
text = '<h3>' + Math.floor(moment.duration(seconds, 'seconds').asDays()) + '</h3><p> days</p>' + '<h3>' + var m = Math.round(moment.duration(((seconds % 86400) % 3600), 'seconds').asMinutes());
Math.floor(moment.duration((seconds % 86400), 'seconds').asHours()) + '</h3><p> hrs</p>' + '<h3>' +
Math.floor(moment.duration(((seconds % 86400) % 3600), 'seconds').asMinutes()) + '</h3><p> mins</p>'; var text = '';
return text; if (d > 0) {
} else if (seconds >= 3600) { text = '<h3>' + d + '</h3><p> day' + ((d > 1) ? 's' : '') + '</p>'
text = '<h3>' + Math.floor(moment.duration((seconds % 86400), 'seconds').asHours()) + '</h3><p> hrs</p>' + + '<h3>' + h + '</h3><p> hr' + ((h > 1) ? 's' : '') + '</p>'
'<h3>' + Math.floor(moment.duration(((seconds % 86400) % 3600), 'seconds').asMinutes()) + + '<h3>' + m + '</h3><p> min' + ((m > 1) ? 's' : '') + '</p>';
'</h3><p> mins</p>'; } else if (h > 0) {
return text; text = '<h3>' + h + '</h3><p> hr' + ((h > 1) ? 's' : '') + '</p>'
} else if (seconds >= 60) { + '<h3>' + m + '</h3><p> min' + ((m > 1) ? 's' : '') + '</p>';
text = '<h3>' + Math.floor(moment.duration(((seconds % 86400) % 3600), 'seconds').asMinutes()) +
'</h3><p> mins</p>';
return text;
} else { } else {
text = '<h3>0</h3><p> mins</p>'; text = '<h3>' + m + '</h3><p> min' + ((m > 1) ? 's' : '') + '</p>';
return text;
} }
return text
} }
String.prototype.toProperCase = function () { String.prototype.toProperCase = function () {