Lots of math to compute time priority