cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
SergioNavarro
Level: Powered On

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
Power Apps Staff CarlosFigueira
Power Apps Staff

Re: Timer control is not accurate

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
Power Apps Staff erga
Power Apps Staff

Re: Timer control is not accurate

@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

Power Apps Staff CarlosFigueira
Power Apps Staff

Re: Timer control is not accurate

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

SergioNavarro
Level: Powered On

Re: Timer control is not accurate

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
thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

SecondImage

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Solution Authors
Top Kudoed Authors (Last 30 Days)
Users online (6,731)