cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
SergioNavarro
Frequent Visitor

Timer control is not accurate

Hello all,

 

I am developing a small app for calculating material flows based on the timer control. Now, that the app is ready to be rolled out, I realized that the timer control is quite inaccurate: after 2 minutes I can see a deviation of around -10 elapsed seconds when comparing it with the Windows time. I am testing the app on an iPhone 6s, which will be the main target equipment.

 

I thank You in advance for a solution/improvement/workaround. 

 

Best Regards,
Sergio

1 ACCEPTED SOLUTION

Accepted Solutions
CarlosFigueira
Power Apps
Power Apps

One possible workaround is to use the Timer not as the stopwatch itself, but as a trigger so that you can update your (internal) stopwatch based on the Now() function.

 

For example, look at the following screen:

Timer.PNG

The Start button has the following properties:

Text: "Start"
OnSelect: UpdateContext({ startTimer: true, initialTime: Now() })

The Stop button updates the 'startTimer' property to stop the timer:

Text: "Stop"
OnSelect: UpdateContext({ startTimer: false })

The Timer control (shown as visible in this screen, but can be hidden in yours) has the following properties:

Duration: 500
Repeat: true
Start: startTimer OnTimerEnd: UpdateContext({ currentTime: Now() })

Finally, the text box that shows the elapsed time below has the following properties:

Text: "Elapsed: " & If(startTimer,
    RoundDown((currentTime - initialTime) * 24 * 60 * 60, 0),
    0)

What those formulas accomplish: whenever the timer is started (based on the 'startTimer' variable), the timer will continuously update the 'currentTime' variable. When it is to be displayed to the user, we subtract it from the initial time when the "stopwatch" was started. Notice that subtracting date/time values returns a value in days, so if we want seconds you need to multiply by 24 (hours) * 60 (minutes) * 60 (seconds)

 

In the example above the accuracy of the elapsed time is of 1 second, but you can go lower. For example, if you set the timer duration to 50 (milliseconds), you should be able to round down to 1 decimal place (instead of 0), and you can have an accuracy to the tenths of a second.

View solution in original post

3 REPLIES 3
erga
Power Apps
Power Apps

@SergioNavarro Thank you for reporting this issue -- our team is investigating the issue and looking to see if there is a workaround. We will provide an update when we finish our investigation. 

 

Eric, Software Engineer, PowerApps Staff

CarlosFigueira
Power Apps
Power Apps

One possible workaround is to use the Timer not as the stopwatch itself, but as a trigger so that you can update your (internal) stopwatch based on the Now() function.

 

For example, look at the following screen:

Timer.PNG

The Start button has the following properties:

Text: "Start"
OnSelect: UpdateContext({ startTimer: true, initialTime: Now() })

The Stop button updates the 'startTimer' property to stop the timer:

Text: "Stop"
OnSelect: UpdateContext({ startTimer: false })

The Timer control (shown as visible in this screen, but can be hidden in yours) has the following properties:

Duration: 500
Repeat: true
Start: startTimer OnTimerEnd: UpdateContext({ currentTime: Now() })

Finally, the text box that shows the elapsed time below has the following properties:

Text: "Elapsed: " & If(startTimer,
    RoundDown((currentTime - initialTime) * 24 * 60 * 60, 0),
    0)

What those formulas accomplish: whenever the timer is started (based on the 'startTimer' variable), the timer will continuously update the 'currentTime' variable. When it is to be displayed to the user, we subtract it from the initial time when the "stopwatch" was started. Notice that subtracting date/time values returns a value in days, so if we want seconds you need to multiply by 24 (hours) * 60 (minutes) * 60 (seconds)

 

In the example above the accuracy of the elapsed time is of 1 second, but you can go lower. For example, if you set the timer duration to 50 (milliseconds), you should be able to round down to 1 decimal place (instead of 0), and you can have an accuracy to the tenths of a second.

View solution in original post

Thank You for Your help, @CarlosFigueira!

 

I could check Your workaround and it works like described. However, I'm afraid I will have to invest some time on implementing features like calculations involving pauses, which were quite straightforward by using the timer control.

 

Is there any chance to have a fix of this issue in the near future? 

 

Thank You again for Your help.

 

Best Regards,

Sergio

 

 

 

 

Helpful resources

Announcements
User Groups Public Preview

Join us for our User Group Public Preview!

Power Apps User Groups are coming! Make sure you’re among the first to know when user groups go live for public preview.

Power Apps Community Call

Monthly Power Apps Community Call

Did you miss the call?? Check out the Power Apps Community Call here!

Power Platform ISV STudio

Power Platform ISV Studio

ISV Studio is the go-to Power Platform destination for ISV’s to monitor & manage applications post-AppSource publish.

Top Solution Authors
Top Kudoed Authors
Users online (63,293)