Hey Bubblers,
I am hoping that one of you brainiacs can point out where I am going wrong with a countdown clock that I have developed using a workflow that takes a specific date in the future and counts down on a frequency that changes the closer the time gets to the future date. Everything seems to work except the seconds which instead of counting down from 59 to 0 go from 30 down to -29.
Detailed explanation
The workflow by initializing the count down measures Days, Hours, Minutes, and Seconds and based on how much time is left to count down, it sets a frequency for updating those measures.
It starts that initialization by extracting the days left in the countdown by subtracting the current date from the countdown future date and formatting that difference as days and then applies the floor function to arrive at the whole number of days left.
Then it adds the number of whole days to the current date and subtracts the resulting date (two days into the future) from the future countdown date, and formats the resulting difference as hours and applies the floor function to get the whole number of hours left.
Then it adds both the number of whole days and the number of whole hours to the current date and subtracts the result from the countdown future date and formats the resulting difference as minutes and applies the floor function to get the number of whole minutes…
It then adds the number of whole days, whole hours and whole minutes to the current date and subtracts the resulting future date from the countdown future to get the total number of seconds left in the countdown.
When I refresh the page every second, I expect this resulting initialized values for Days, Hours, Minutes and Seconds to look like the countdown but the seconds do not behave as expected. The countdown in seconds only gets as high as 30 seconds and when the second count reaches zero, the count goes into negative numbers down to -29, at which point the count starts again at positive 30.
I have tried creating the future dates based on adding Days, Hours, Minutes to the current date using +Day, +Hours +Minutes as well as adding +seconds using the Number of Whole Days * 86,400 seconds, Number of Hours * 3600 seconds but both give the unexpected negative numbers.
I have provided a detailed screenshot of each step in the workflow that relates to the initialization. The strange negative numbers occur up to step 10 in the workflow.
I have included one final shot that shows how the system changes the frequency of the countdown update as the countdown gets closer for anyone that is interested.
The attached video shows me giving a page refresh which should emulate the countdown at a frequency of about 1 second.
By my understanding of how dates and the various date functions in Bubble work, the seconds should never be less than 0.
Is this a bug or am I doing something wrong.
Cheers,
KH
Screenshots showing workflow config panels
Video of Countdown emulation by page refresh every second (or just about)