Answer the question
In order to leave comments, you need to log in
How to find out the percentage of elapsed time?
I display to the visitor the amount of % elapsed time as a loading bar.
There is:
$progress = $TOTAL - ($TOTAL- ($NOW - $START) / $INTERVAL * $TOTAL);
/*echo 'Осталось: ' . date('i мин. s сек.', $START + $INTERVAL - $NOW);*/
Answer the question
In order to leave comments, you need to log in
Well, if you open the brackets, then the presented formula is equivalent to the following:
Everything else is correct.
As far as I understand, you display the percentage of the past 10 minutes from the time START to NOW
. I just don’t understand what TOTAL is? Is it 100% or what?
that is, time elapsed:
passed = now - start
This is:
percentage = 100% * passed/interval = 100 * (now-start)/interval // final formula
of the percentage of your INTERVAL variable.
As far as I understand this is progress.
To check the correctness write tests:
Check the boundary conditions:
at 0 elapsed time:
passed = now - start = 0
percentage = 100% * 0/interval = 0%
at time equal to now = interval+start
passed = now - start = interval+start -start=interval
percentage = 100% * passed/interval = 100% * interval/interval = 100%
in the middle will be 50% respectively.
Did you want to get it?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question