I am having total Minutes and i want to convert that total minutes into number of Days, Hours and Minutes format.
var duration = getControlValue('incident','incident_open_duration');
var formattedDuration = duration/24/60 + ":" + duration/60%24 + ':' + duration%60);
alert(formattedDuration);
If the total minutes is 8289.66 , the above line of code returns 5.756708333333333:18.161:9.659999999999854
I don't need decimals, i want to eliminate and round off them so i used Math.floor(time/24/60) + ":" + Math.floor(time/60%24) + ':' + Math.floor(time%60) but unfortunately my tool is not supporting Math.floor function
Do we have any other way of achieving this ?
You can use double Bitwise_NOT
var duration = 8289.66;
var cleanDuration = ~~(duration / 24 / 60) + ":" + ~~(duration / 60 % 24) + ':' + ~~(duration % 60);
console.log(cleanDuration);
//Suggested by @STh format if you need a format like HH:mm:ss
var formattedDuration = String(~~(duration / 24 / 60)).padStart(2, '0') + ":" + String(~~(duration / 60 % 24)).padStart(2, '0') + ':' + String(~~(duration % 60)).padStart(2, '0')
console.log(formattedDuration);
The snippet above adds leading zeros if the hours / minutes / seconds are only one digit via the padStart method.
Another alternative is Left_shift, Right_shift or Unsigned right shift with 0
var duration = 8289.66;
var formattedDuration = ((duration / 24 / 60) << 0) + ":" + ((duration / 60 % 24) << 0) + ':' + ((duration % 60) << 0);
console.log("Left Shift Example" , formattedDuration);
var formattedDuration = ((duration / 24 / 60) >> 0) + ":" + ((duration / 60 % 24) >> 0) + ':' + ((duration % 60) >> 0);
console.log("Rigth Shift Example" , formattedDuration);
var formattedDuration = ((duration / 24 / 60) >>> 0) + ":" + ((duration / 60 % 24) >>> 0) + ':' + ((duration % 60) >>> 0);
console.log("Unsigned right shift Example" , formattedDuration);
Or Bitwise_OR with 0
var duration = 8289.66;
var formattedDuration = ((duration / 24 / 60)|0) + ":" + ((duration / 60 % 24)|0) + ':' + ((duration % 60)|0)
console.log(formattedDuration);
There are the GET Dates method, with which you can extract the components from a date. If you only have the duration, you can, e.g., use the new Date(duration_in_ms) constructor.
So, to fit your use case, the code is:
const x = new Date(duration * 60 * 1000).getXXX()
where getXXX is one of the GET Dates-methods.