Skip to content

Instantly share code, notes, and snippets.

@dmjcomdem
Created June 14, 2017 17:02
Show Gist options
  • Save dmjcomdem/631014d41947f85993b290fe3cd7bd99 to your computer and use it in GitHub Desktop.
Save dmjcomdem/631014d41947f85993b290fe3cd7bd99 to your computer and use it in GitHub Desktop.
_startTimer(){
this._stopTimer();
let timeSeconds = 1;
this._timerInterval = this.$interval(() => {
timeSeconds += 1;
this.onlineTimeText = this._formatTime(timeSeconds);
}, 1000);
this.onlineTimeText = this._formatTime(timeSeconds)
}
_stopTimer(){
this.$interval.cancel(this._timerInterval);
this.onlineTimeText = "";
}
_formatTime(seconds){
const displayZero = value => value < 10 ? "0"+value : String(value);
const displaySeconds = displayZero(seconds%60);
const minutes = Math.floor(seconds/60);
const displayMinutes = displayZero(minutes%60);
const hours = Math.floor(minutes/60);
if (hours) return `${hours}:${displayMinutes}:${displaySeconds}`;
else return `${displayMinutes}:${displaySeconds}`;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment