mrchimp / tock

Timer Object/Class. Kickass!
MIT License
237 stars 33 forks source link

How to pause? #11

Closed daver182 closed 10 years ago

daver182 commented 10 years ago

I looking for the option to pause the timer, it's posible?

mrchimp commented 10 years ago

Hi Daver. There is no pause method as such, but it can be done.

For timers (countdown = false), it's simple:

if (tock.go) {
    tock.stop();
} else {
    tock.start();
}

For countdown timers it is a bit more complicated as start() requires a parameter. So you would have to do something like:

if (tock.go) {
    tock.pause_time = tock.lap();
    tock.stop();
} else {
    tock.start(tock.pause_time);
}

I should probably just add a pause() method...

daver182 commented 10 years ago

Hi, thanks for the answer but I have once concern, the solution will remember the last value?, I mean it will start in the point where stops?

mrchimp commented 10 years ago

I've made a small change to the second piece of code above. It will remember the time, yes.

daver182 commented 10 years ago

Thanks again, I feel a little dumb but, can this work for not a countdown?

mrchimp commented 10 years ago

Pull the latest changes and you can just use pause().