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) {
var text;
if (seconds >= 86400) {
text = '<h3>' + Math.floor(moment.duration(seconds, 'seconds').asDays()) + '</h3><p> days</p>' + '<h3>' +
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>';
return text;
} else if (seconds >= 3600) {
text = '<h3>' + 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>';
return text;
} else if (seconds >= 60) {
text = '<h3>' + Math.floor(moment.duration(((seconds % 86400) % 3600), 'seconds').asMinutes()) +
'</h3><p> mins</p>';
return text;
var d = Math.floor(moment.duration(seconds, 'seconds').asDays());
var h = Math.floor(moment.duration((seconds % 86400), 'seconds').asHours());
var m = Math.round(moment.duration(((seconds % 86400) % 3600), 'seconds').asMinutes());
var text = '';
if (d > 0) {
text = '<h3>' + d + '</h3><p> day' + ((d > 1) ? 's' : '') + '</p>'
+ '<h3>' + h + '</h3><p> hr' + ((h > 1) ? 's' : '') + '</p>'
+ '<h3>' + m + '</h3><p> min' + ((m > 1) ? 's' : '') + '</p>';
} else if (h > 0) {
text = '<h3>' + h + '</h3><p> hr' + ((h > 1) ? 's' : '') + '</p>'
+ '<h3>' + m + '</h3><p> min' + ((m > 1) ? 's' : '') + '</p>';
} else {
text = '<h3>0</h3><p> mins</p>';
return text;
text = '<h3>' + m + '</h3><p> min' + ((m > 1) ? 's' : '') + '</p>';
}
return text
}
String.prototype.toProperCase = function () {