Skip to content

Instantly share code, notes, and snippets.

@srph
Created May 21, 2019 12:39
Show Gist options
  • Save srph/f7076e0a019e1230ae84ba8fbe6fde88 to your computer and use it in GitHub Desktop.
Save srph/f7076e0a019e1230ae84ba8fbe6fde88 to your computer and use it in GitHub Desktop.
JS: Get remaining time from seconds
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