Skip to content

Instantly share code, notes, and snippets.

@ig10
Created October 27, 2015 13:49
Show Gist options
  • Save ig10/de17829b7eeb89c067c7 to your computer and use it in GitHub Desktop.
Save ig10/de17829b7eeb89c067c7 to your computer and use it in GitHub Desktop.
Translate Minutes to hours and minutes
function inHoursFilter(mins) {
// Return String with Qty of Hours and Mins
// REFACTOR!
var total = Math.round((parseFloat(mins)/60)*100)/100,
hours = Math.floor(total),
minutes = Math.round(parseFloat('0.'+ total.toString().split('.')[1]) * 100 ) / 100,
result = "";
if( hours === 0) {
return mins + ' mins';
} else {
result += hours.toString() + ' hr';
}
if( !isNaN(minutes) && minutes !== 0 ) {
minutes = Math.round(minutes*60);
result += ' ' + minutes.toString() + ' mins';
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment