Created
March 22, 2018 18:33
-
-
Save jhsuZerion/8c7c4c867b7af77dfc7e40b357573f50 to your computer and use it in GitHub Desktop.
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
/** | |
* Convert a whole number of minutes into an hour/minute string | |
* @param {number} m number of minutes, will be truncated | |
* @return {string} string of converted time in hours/minutes | |
* Example: 1hr, 1hr 40 min, 2 hrs 15 min | |
*/ | |
function convertMinutesToHours(m) { | |
// truncate number of minutes | |
m = Math.floor(m); | |
var hours = Math.floor(m / 60); | |
var minutes = m % 60; | |
var output = ""; | |
if(hours > 0) { | |
output += String(hours) + " "; | |
output += (hours > 1) ? "hrs" : "hr"; | |
} | |
if(minutes > 0) { | |
if(output.length > 0) output += " "; | |
output += String(minutes) + " min"; | |
} | |
return output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment