diff --git a/cypress/integration/utils.js b/cypress/integration/utils.js index e30d922429..083a03294a 100644 --- a/cypress/integration/utils.js +++ b/cypress/integration/utils.js @@ -49,6 +49,24 @@ context("Utils", () => { seconds: 0, }); }); + + run_util("seconds_to_duration", 60 * 60, { hide_seconds: 1 }).then((duration) => { + expect(duration).to.deep.equal({ + days: 0, + hours: 1, + minutes: 0, + seconds: 0, + }); + }); + + run_util("seconds_to_duration", 15 * 60, { hide_seconds: 1 }).then((duration) => { + expect(duration).to.deep.equal({ + days: 0, + hours: 0, + minutes: 15, + seconds: 0, + }); + }); }); it("should parse days, hours, minutes and seconds", () => { diff --git a/frappe/public/js/frappe/utils/utils.js b/frappe/public/js/frappe/utils/utils.js index 5a5b75bdeb..37e0980cfd 100644 --- a/frappe/public/js/frappe/utils/utils.js +++ b/frappe/public/js/frappe/utils/utils.js @@ -1144,8 +1144,6 @@ Object.assign(frappe.utils, { seconds_to_duration(seconds, duration_options) { const floor = seconds > 0 ? Math.floor : Math.ceil; - const round_base_60 = (seconds) => floor(seconds / 60 + (seconds > 0 ? 0.5 : -0.5)); - const total_duration = { days: floor(seconds / 86400), // 60 * 60 * 24 hours: floor((seconds % 86400) / 3600), @@ -1159,7 +1157,7 @@ Object.assign(frappe.utils, { } if (duration_options && duration_options.hide_seconds) { - total_duration.minutes += round_base_60(total_duration.seconds); + total_duration.minutes += Math.round(total_duration.seconds / 60); total_duration.seconds = 0; }