angular-timer icon indicating copy to clipboard operation
angular-timer copied to clipboard

resume timer

Open alainib opened this issue 8 years ago • 7 comments

I'm trying to make a stop & resume action. This is not working for me. For example the time left is 50seconds, i press "stop" (the left time stop) and wait 10 secondes, then press resume, the time jump to 40 seconds instead of 49. It is like it stop only the display !

my html

<timer end-time="aaaa" id="poll-server" interval="5000"> {{hours}}:{{minutes}}:{{seconds}} </timer> <button ng-click="stopTimer()" >stopTimer</button> <button ng-click="resumeTimer()">resumeTimer</button>

In controller :

 $scope.stopTimer = function (){
     $scope.$broadcast('timer-stop');
     $scope.timerRunning = false;
  };

  $scope.resumeTimer = function (){
     $scope.$broadcast('timer-resume');
     $scope.timerRunning = false;
  };

I'm using the angular-timer - v1.3.4

thanks

alainib avatar Oct 04 '16 12:10 alainib

+1 for me resume also is not working

sercul avatar Oct 07 '16 12:10 sercul

I had similar problem. Here is my html template:

<timer start-time="some date" autostart="false" interval="1000">
<% hhours %>:<%mminutes%>:<%sseconds%>
</timer>

And the problem was same to what @alainib is described. I paused timer then unpause it later and it's starts count not from stopping date but from start-time value I set before in the template.

I solved this problem by editing this lines:

if ($attrs.startTime !== undefined){
   $scope.millis = moment().diff(moment($scope.startTimeAttr));
}

The problem here is that this part it's skipping $scope.startTime date value that changed by calling $scope.stop and $scope.resume functions, so I had to change those line to this:

if ($attrs.startTime !== undefined) {
   if($scope.startTime === null) {
      $scope.millis = moment().diff(moment($scope.startTimeAttr));
   } else {
      $scope.millis = moment().diff(moment($scope.startTime));
   }
}

Or smaller:

if ($attrs.startTime !== undefined) {
    $scope.millis = $scope.startTime === null ? moment().diff(moment($scope.startTimeAttr)) : $scope.millis = moment().diff(moment($scope.startTime));	
}

Hope this would be helpful to someone.

scofield-ua avatar Dec 10 '16 12:12 scofield-ua

Your help is very appreciated thanks I tried your fix but it doesn't work for me.

    function calculateTimeUnits() {
       var timeUnits = {}; //will contains time with units
       
       console.log("calculateTimeUnits"+$attrs.startTime); // always undefined 
       
       if ($attrs.startTime !== undefined){
         if ($attrs.startTime !== undefined) {

           // this logs are never called
           console.log("$scope.startTimeAttr"+$scope.startTimeAttr);
           console.log("$scope.startTimeAttr"+$scope.startTime);
           if($scope.startTime === null) {
             $scope.millis = moment().diff(moment($scope.startTimeAttr));
           } else {
             $scope.millis = moment().diff(moment($scope.startTime));
           }
         }
       } 
       ....

How did you start & stop timer please ? I use this :

      $scope.stopTimer = function (){
        $scope.$broadcast('timer-stop');
      };

      $scope.resumeTimer = function (){
        $scope.$broadcast('timer-resume');
      };

alainib avatar Dec 22 '16 13:12 alainib

When I used the timer as a directive in Ionic 1 Framework, I has to broadcast events as $rootScope.$broadcast in order to for the directive to see them. However this also worked and is probably a better solution. Use commands like document.getElementByID if you have multiple directives and give them and ID combined with document.getElementsByTagName('timer')[0].stop() to stop and "[0].start" to start.

See: https://searchcode.com/codesearch/view/85611717/

wivancic avatar Dec 22 '16 15:12 wivancic

@alainib make suer your "timer library" script looks same like this and especially this part.

Here is demo with modified script and with creator's script.

scofield-ua avatar Dec 27 '16 17:12 scofield-ua

happy new year @scofield-ua thanks for taking time to make the codepen I try your code and work, in fact i use end-time option and still doesn't work

http://codepen.io/anon/pen/rjBQWO?editors=1010

thanks

alainib avatar Jan 02 '17 10:01 alainib

@scofield-ua @siddii @alainib Timer resume functionality for multiple timers Hi I have a list of multiple timers where a user can select which timer he wishes to resume from a list of timers.

user 1: test, time accrued: 5 seconds

user 2: test 2, time accrued: 10 seconds ........ How to set timer directive which is running to make it resume from user 1 time & resume from user 2 when i select user 2 time.

start-time attribute isn't working can you explain how to achieve this.

how can i resume my timer from a predefined time from my controller because i'm using a one single timer that will record and push events according to the list item selected. The mutilple timer example doesn't works for me because it is using different timers and not a single timer directive.

amaheshwari-systango avatar Jan 18 '17 06:01 amaheshwari-systango