Last active
December 11, 2020 13:00
-
-
Save angeloevangelista/ae9470b4572dd04e0af1a0aade9ef682 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
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