Created
August 12, 2019 04:40
-
-
Save SanichKotikov/4d3d85cbec823bbfed860fea6052f92c 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 SECOND = 1000; | |
const MINUTE = SECOND * 60; | |
const HOUR = MINUTE * 60; | |
const DAY = HOUR * 24; | |
const TIME = { | |
second: SECOND, | |
minute: MINUTE, | |
hour: HOUR, | |
day: DAY, | |
}; | |
const formatNumber = (n: number) => n < 10 ? `0${n}` : n; | |
function getTimerData(next: number) { | |
const days = Math.floor(next / TIME.day); | |
const hours = Math.floor(next / TIME.hour - days * 24); | |
const minutes = Math.floor(next / TIME.minute - days * 24 * 60 - hours * 60); | |
const seconds = Math.floor(next / TIME.second - minutes * 60 - days * 24 * 60 * 60 - hours * 60 * 60); | |
return { | |
days, | |
hours: formatNumber(hours), | |
minutes: formatNumber(minutes), | |
seconds: formatNumber(seconds), | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment