Skip to content

Commit

Permalink
changed formatSecond to show decimals
Browse files Browse the repository at this point in the history
  • Loading branch information
ayasayadi1 committed Apr 29, 2024
1 parent 353b3f7 commit 10ac837
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 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,13 @@
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") {
//round to 1 decimal
result[dict[i].k] = Math.round(timeLeft / dict[i].v * 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 10ac837

Please sign in to comment.