I actually search how can I add an option to have days in extra to my code. If someone can help I will be very very granted !
const portionTime = durationInSeconds => {
let hours = durationInSeconds / 3600;
let mins = (durationInSeconds % 3600) / 60;
let secs = (mins * 60) % 60;
hours = Math.trunc(hours);
mins = Math.trunc(mins);
if (!hours && !mins && !secs) {
return "None";
}
if (hours) {
if (mins) {
return secs
? `${hours} hr ${mins} min & ${secs} sec`
: `${hours} hr & ${mins} min`;
} else {
return secs ? `${hours} hr & ${secs} sec` : `${hours} hr`;
}
} else {
if (mins) {
return secs ? `${mins} min & ${secs} sec` : `${mins} min`;
} else {
return secs ? `${secs} sec` : `None`;
}
}
};```
I used the modulus
%for the hours, and calculated the days normally the same way you did originally for the hours.I also implemented the conditions in a different way to make it a bit shorter.