Skip to content

Instantly share code, notes, and snippets.

@SanichKotikov
Created August 12, 2019 04:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SanichKotikov/4d3d85cbec823bbfed860fea6052f92c to your computer and use it in GitHub Desktop.
Save SanichKotikov/4d3d85cbec823bbfed860fea6052f92c to your computer and use it in GitHub Desktop.
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