Created
March 16, 2017 09:33
-
-
Save bhavyaw/a7f8663b28ea1f115021cad683e3ce30 to your computer and use it in GitHub Desktop.
Minutes to HH:mm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
formatMinutesToDuration(durationInMinutes){ | |
let formattedDuration = ``; | |
if(durationInMinutes){ | |
let derivedHours = round( (durationInMinutes / 60 ),3); | |
let hours = Math.trunc(derivedHours); | |
let derivedMinutes = Math.abs(derivedHours - Math.floor(derivedHours)); | |
let minutes = Math.trunc(derivedMinutes * 60); | |
let hoursFormatted = hours ? ( (hours < 10) ? `0${hours}` : hours ) : "00"; | |
let minuteFormatted = minutes ? ( (minutes < 10) ? `0${minutes}` : minutes ) : "00"; | |
formattedDuration = `${hoursFormatted}:${minuteFormatted}`; | |
} | |
return formattedDuration; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment