Merge pull request #14493 from frappe/fix-negative-duration

fix: handle negative duration
This commit is contained in:
mergify[bot] 2021-10-19 09:34:11 +00:00 committed by GitHub
commit 8e2cf038c4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1049,18 +1049,20 @@ Object.assign(frappe.utils, {
return duration;
},
seconds_to_duration(value, duration_options) {
let secs = value;
let total_duration = {
days: Math.floor(secs / (3600 * 24)),
hours: Math.floor(secs % (3600 * 24) / 3600),
minutes: Math.floor(secs % 3600 / 60),
seconds: Math.floor(secs % 60)
seconds_to_duration(seconds, duration_options) {
const round = seconds > 0 ? Math.floor : Math.ceil;
const total_duration = {
days: round(seconds / 86400), // 60 * 60 * 24
hours: round(seconds % 86400 / 3600),
minutes: round(seconds % 3600 / 60),
seconds: round(seconds % 60)
};
if (duration_options.hide_days) {
total_duration.hours = Math.floor(secs / 3600);
total_duration.hours = round(seconds / 3600);
total_duration.days = 0;
}
return total_duration;
},