Stopwatch that runs in the background of the website?

Hi there, I am still relatively new to bubble,

Currently I am using a timer on a page that is displayed to count how many seconds a machine has been down. The timer was built with this tutorial:

In essence, it uses the current date and time in the real world as well as the current date and time which starts when you click a start button (by set states elemental action).

However, every time I leave the page and come back the timer resets and there are no actions that reset any data that involves this. So I was wondering how can I make that time keep running whilst im on other pages of the app.

Below are screenshots of a more in depth view of how the timer I built works.


Group Timer Screenshot

Text Timer Screenshot
Capture

Thank you for any help!

You can’t stop time from running…

So you just need to know the start and end times.

Unfortunately the end times are not known, as in my scenario when a machine is fixed and up and running would be the end time. As of then the start time is when they first report it and the stopwatch keeps ticking up per second.

Is it safe to assume there is no way around this issue?

The (current) end time is now (the current date/time)

I’m not sure I understand what the issue is?..

A timer (by definition) calculates the difference between a given time (in the past) and the current time… or the current time and a future time…

As long as you know both the target time and the current time you have a working timer.

Basically the issue is that I have a stopwatch counting up on my downtime page, and would like that to keep running whilst navigating other pages. Currently, if I leave the downtime page and return back to it, the stopwatch resets back to 0 (which makes sense cause the start time is set to the page’s date/time once loaded).

The application for this feature in this scenario is when a machine goes down, the machine operator comes to this downtime page and the stopwatch starts ticking up to keep track of how long the machine is down for. Once the machine is repaired, they click a submit button and the time displayed for how long it took the machine to be back up and running (from when it was down) is submitted to a database.

Again the issue is whilst the machine operator is on this downtime page with the stopwatch running, they may need to navigate to other pages on the app to do other things whilst the machine is down, but once they leave the page that stopwatch resets. Is there a way for the machine operator to navigate other pages of the app, then come back to the downtime page without the stopwatch resetting back to 0?

Exactly… so that’s your issue.

Don’t use the page load time as the start time. Use the time you actually start the timer.

Apologies I have explained that bit poorly, the start time is when the button start is clicked on a popup when the page is loaded as seen per the screenshot below…

But when I load the page as seen per the screenshot the timer is still reset to 0m 0s.
Just incase should I share my bubble editor on here for a better understanding? Apologies for any poor explanation again still kinda new to bubble.

I do something similar in my app.

I struggled to figure this out myself and determined in the end that I was REALLY overthinking it.

All I had to do was this:

  1. I know the “start time” (which for you is when the unit went down).
  2. I know the current time (which for you is…well…current time).

So I all I is calculate the difference between the two and use that for my display.

It looks like you might have already figured out how to DISPLAY the time the unit has been down.

Just maybe use this to CALCULATE the time the unit has been down.

Yes, I understand exactly what you’re trying to do, and what you’re doing wrong…

That’s because you’re not saving the start time anywhere.

You just need to save the start time, then use that saved time as the time from which to calculate the time difference.

So I save the start time into a database? and when the page is reloaded do I use a “search for” function to find the start time in the database and use that as the subtraction of the current time?

Jeepers, I didn’t even see where he wasn’t saving the timestamp for when the unit went down.

Yeah, @srabayah, you definitely need to save the time.

If I manage it to calculate the differences when reloading the page can I still manage it to keep ticking up per second when the page is loaded with the calculated time differences?

E.g. Page is loaded, it does the current time - start time, (then the hard part for me at least) every 1 second it keeps updating that calculated time?

I don’t know exactly how your timer is built.

But I would assume so, as long as your timer is always using the difference between the start time and current time and displaying that total time.

1 Like

Alright will give it a go now, might take me a while as im new to bubble but hopefully it will work!

Exactly…

1 Like

Gonna have a crack at it, im new to bubble so will take me a bit of time but will update if I can, thanks for the help!

@adamhholmes @firstfifteensoftware
I did it! Thanks to all your help!
I really wish you guys were there to explain to me the first time I watched Interstellar cause I would’ve understood it the first time.
Thank you both so much appreciate the help :heart:

1 Like

Thanks for the thanks.

But @adamholmes really did most of the work.

Hey!

Read the entire thread and I have a problem the method above doest solve (I think)

My stopwatch works exactly like described above so every time the user refreshes the page - the stopwatch count the diff and shows the correct time count

My app is wrapped as native. My problem is for situation where the user minimizes the app and then re-opens it. In those cases the stopwatch continues the count from where it last stopped stopped before minimizing the app…

I guess It acts like this because the current date/time is not updated after mibimizing the app because it does.not require a refresh of the page unlike on a browser?

Would love some help on that…
Thanks a lot!

This topic was automatically closed after 70 days. New replies are no longer allowed.