Having trouble with my timer functionality. It seems I may have over-complicated things, but what I really need is the ability to count from 00:00 to 45:00 and pause and resume the timer within those limits.
Currently, my timer code looks like this:
<timer id="timer" autostart="false" start-time="coutingStart" end-time="countingEnd">{{mminutes}}:{{sseconds}}</timer>
The initialization for countingStart
and countingEnd
is as follows:
var time = (45 * 60000);
$scope.countingStart = (new Date()).getTime();
$scope.countingEnd = (new Date()).getTime() + time;
While this code works, a button triggers the timer to start counting from 00:00. However, when pausing and then resuming the timer, there's an issue where time appears to be lost.
Functions for pausing and resuming the timer are in place:
$scope.PauseGame = function() {
switch ($scope.periodNum) {
case 1:
document.getElementById('timer').stop();
$scope.PauseIsActive = true;
break;
case 2:
document.getElementById('timer').stop();
$scope.PauseIsActive = true;
break;
}
};
$scope.ResumeGame = function() {
switch ($scope.periodNum) {
case 1:
document.getElementById('timer').resume();
$scope.PauseIsActive = false;
break;
case 2:
document.getElementById('timer').resume();
$scope.PauseIsActive = false;
break;
}
};
Although these functions work, there's an issue with losing time when pausing and resuming at specific intervals.
I suspect the problem lies within how $scope.counterStart
and $scope.counterEnd
are calculated. How can I ensure accurate timing from 00:00 to 45:00 while maintaining the ability to pause and resume the timer?
The Angular timer utilizes the Date object and milliseconds for time tracking, suggesting a different approach might be necessary to achieve the desired functionality. Any insights on achieving accurate time measurement and control are appreciated.
Thank you.