Stopwatch using Tizen Time API

Stopwatch is a time based utility that can be used to measure the amount of time elapsed from a particular time until a time of interest reached or an event occurs.

Using the application

There are three buttons. Initially all buttons are enabled.

1.     Start: - Initially the stopwatch is in zero position, “00:00:00:000”. On pressing the “Start” button, the stopwatch starts counting the time elapsed from the point of start.

After clicking on the “Start” button, “Reset” and “Start” buttons are disabled and “Stop” button is enabled.

2.     Stop: - On pressing the “Stop” button, the calculation of elapsed time gets stopped and is shown by the stopwatch.

After clicking on the “Stop” button, “Start’ and “Reset” buttons are enabled and “Stop” button is disabled.

3.     Reset: - On pressing the “Reset” button, stopwatch is reset to the initial position i.e. “00:00:00:000”.

After clicking on the “Reset” button “Start” button is enabled and “Reset” and “Stop” buttons are disabled.

 

Fig: Snap shot of stopwatch

Code snippet to start stopwatch
Initially the position of stopwatch is zero. Clicking on the “Start” button fetches the current time and invokes the Counter() method, which counts the difference between the current and the start time. ”setTimeout()” is a callback method used for calling the Counter() in every 10 milliseconds.

function Start() {  
       startTime = tizen.time.getCurrentDateTime();
       Counter();
       ...
}
//code snippet for counter

function Counter() {
       var duration = tizen.time.getCurrentDateTime().difference(startTime);
       Refresh = setTimeout('Counter()',10);
       Time_format(duration.length + Diff);
       ...
}

 

Code snippet to stop stopwatch
After clicking on the “Stop” button, the counter stops and shows the difference between the stop and the start time. ”clearTimeout()” method is used to clear the interval.

function Stop() {      
       clearTimeout(Refresh);
       var duration = tizen.time.getCurrentDateTime().difference(startTime);
       Diff += duration.length;
      ...
}

 

Code snippet to reset stopwatch
After clicking on the “Reset” button, the stopwatch is set to initial position. Zero is assigned to the global variable Diff.

function Reset() {      
       Stp.innerText ="00:00:00:000";
       Diff = 0;
       ...
}

 

Build Requirements:
The application is built for devices with Tizen 2.0 firmware.
SDK Environment used:  2.0.0a2

 

Appendix:
Sample app attached.

 

File attachments: