Skip to content

Instantly share code, notes, and snippets.

@angeloevangelista
Last active December 11, 2020 13:00
Show Gist options
  • Save angeloevangelista/ae9470b4572dd04e0af1a0aade9ef682 to your computer and use it in GitHub Desktop.
Save angeloevangelista/ae9470b4572dd04e0af1a0aade9ef682 to your computer and use it in GitHub Desktop.
const convertMinutes = (totalInMinutes, short = false) => {
let hours = Math.floor(totalInMinutes / 60).toFixed(0);
const minutes = totalInMinutes % 60;
const days = Number(Math.floor(hours / 24).toFixed(0));
hours = hours % 24;
let result = '';
if (short) {
if (!!days) {
return `${days} dia(s)`;
}
if (!!hours) {
return `${hours} h`;
}
if (!!minutes && !days) {
return `${minutes} min`;
}
}
if (!!days) {
result += `${days} dia(s)`;
}
if (!!hours) {
result += !!days? ` e ${hours} h`: `${hours} h`;
}
if (!!minutes && !days) {
result += !!hours? ` e ${minutes} min`: `${minutes} min`;
}
return result;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment