Created
June 14, 2017 17:02
-
-
Save dmjcomdem/631014d41947f85993b290fe3cd7bd99 to your computer and use it in GitHub Desktop.
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
_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