Skip to content

Commit

Permalink
Merge pull request #5140 from Countly/SER-1353
Browse files Browse the repository at this point in the history
[SER-1353] changed formatSecond to show decimals
  • Loading branch information
Cookiezaurs authored May 2, 2024
2 parents a02ce46 + 7828c81 commit 5f6e81b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
for (var i = 0; i < chartData.length; i++) {
graphData[0].push(chartData[i].c ? chartData[i].c : 0);
graphData[1].push(chartData[i].s ? chartData[i].s : 0);
graphData[2].push(chartData[i].dur ? chartData[i].dur / (chartData[i].c || 1) : 0);
let avgDur = (chartData[i].dur || 0) / (chartData[i].c || 1);
graphData[2].push(avgDur < 0.1 ? 0 : avgDur);
if (chartData[i].c) {
count += chartData[i].c;
}
Expand Down
14 changes: 12 additions & 2 deletions frontend/express/public/javascripts/countly/countly.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -4526,7 +4526,7 @@
* @example trimTo = 2, "Xh Xm Xs" result will be trimmed to "Xh Xm"
*/
countlyCommon.formatSecond = function(second, trimTo = 5) {
var timeLeft = parseInt(second);
var timeLeft = parseFloat(second);
var dict = [
{k: 'year', v: 31536000},
{k: 'day', v: 86400},
Expand All @@ -4537,7 +4537,17 @@
var result = {year: 0, day: 0, hour: 0, minute: 0, second: 0};
var resultStrings = [];
for (var i = 0; i < dict.length && resultStrings.length < 3; i++) {
result[dict[i].k] = Math.floor(timeLeft / dict[i].v);
if (dict[i].k === "second") {
if (timeLeft < 0.1) {
result.second = 0;
}
else {
result.second = Math.round(timeLeft * 10) / 10;
}
}
else {
result[dict[i].k] = Math.floor(timeLeft / dict[i].v);
}
timeLeft = timeLeft % dict[i].v;
if (result[dict[i].k] > 0) {
if (result[dict[i].k] === 1) {
Expand Down

0 comments on commit 5f6e81b

Please sign in to comment.