Merge pull request #14493 from frappe/fix-negative-duration
fix: handle negative duration
This commit is contained in:
commit
8e2cf038c4
1 changed files with 10 additions and 8 deletions
|
|
@ -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;
|
||||
},
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue