angular timer - .stop() and .resume() problems
<p>I'm having a bit trouble with my timer. I might have made it more complicated than it should be because what I need is the following: </p>

<blockquote>
  <p>I need to count from 00:00 to say 45:00 and I need to be able to stop and resume the timer within these boundaries.</p>
</blockquote>

<p>Right now I've got this timer code: </p>

<pre><code>&lt;timer id="timer" autostart="false" start-time="coutingStart" end-time="countingEnd"&gt;{{mminutes}}:{{sseconds}}&lt;/timer&gt;
</code></pre>

<p><code>countingStart</code> and <code>countingEnd</code> initializes like this:</p>

<pre><code>var time = (45 * 60000); // should give me 45 minutes of time.
$scope.countingStart = (new Date()).getTime();
$scope.countingEnd = (new Date()).getTime() + time;
</code></pre>

<p>This code above works, atleast I think it does.
I've got a button with this function on it:</p>

<pre><code>$scope.startGame = function() {
    $scope.gameIsLive = true;
    document.getElementById('timer').start();
};
</code></pre>

<p>which starts my counter, no problem, it starts from 00:00 atleast.
But then I have buttons with these functions aswell which is where I'm having my problem.</p>

<pre><code>$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;
    }
};
</code></pre>

<p>Both <code>pauseGame()</code> and <code>resumeGame()</code> works as expected. They are pausing and resuming the timer. But, when I pause the timer on say <code>00:10</code> and count for myself 10 seconds and then resume it the timer now stands on <code>00:20</code> which made me just lost 10 seconds of the timer.</p>

<p>I can think that my problem is inside the instantiating of <code>$scope.counterStart</code> and <code>$scope.counterEnd</code>. But I am not sure. How can I count from 00:00 to 45:00 and still being able to stop and resume the clock when needed?</p>

<p>Angular timer uses the Date object and milliseconds to count time so I suppose I have to use this approach to get 00:00 which is now and count 45 minutes forward. Can it be done otherwise with stop and resume functionality?</p>

<p>Thanks.</p>