Created
May 21, 2019 12:39
-
-
Save srph/f7076e0a019e1230ae84ba8fbe6fde88 to your computer and use it in GitHub Desktop.
JS: Get remaining time from seconds
This file contains hidden or 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
interface RemainingTimeValue { | |
hours: number | |
minutes: number | |
seconds: number | |
} | |
/** | |
* Get remaining time from seconds | |
* | |
* Used by `toReadableTime` and `distanceInWordsAbbreivated` | |
*/ | |
export default function getRemainingTime(seconds: number): RemainingTimeValue { | |
const hh = Math.floor(seconds / 3600) | |
const mm = Math.floor((seconds % 3600 / 60)) | |
const ss = Math.floor(seconds % 60) | |
return { | |
hours: hh, | |
minutes: mm, | |
seconds: ss | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment