Skip to content

Instantly share code, notes, and snippets.

@jhsuZerion
Created March 22, 2018 18:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhsuZerion/8c7c4c867b7af77dfc7e40b357573f50 to your computer and use it in GitHub Desktop.
Save jhsuZerion/8c7c4c867b7af77dfc7e40b357573f50 to your computer and use it in GitHub Desktop.
/**
* 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