I found this great method on Stackoverflow to convert duration from ss into hh.mm.ss and I tried to call it within the render () section of the page. Many attempts, but not yet successful. I think I am missing something in the syntax of the arrow function, but can't find out what.
This is the method I slightly edited for my purpose:
formatTime(duration) {
d = Number(duration);
var h = Math.floor(d / 3600);
var m = Math.floor(d % 3600 / 60);
var s = Math.floor(d % 3600 % 60);
var hDisplay = h > 0 ? h + (h == 1 ? " hour, " : " hours, ") : "";
var mDisplay = m > 0 ? m + (m == 1 ? " minute, " : " minutes, ") : "";
var sDisplay = s > 0 ? s + (s == 1 ? " second" : " seconds") : "";
return hDisplay + mDisplay + sDisplay;
}
And this is my render()
section, where I would like to call formatTime()
, passing song.duration
as an argument of the method (full code here):
render() {
return (
//[...]
<td {() => this.formatTime(song.duration)}>
{formatTime(song.duration)} </td>
//[...]
}