Move contest phase computation out of render_params
Add tests for phase computation and fix a few minor bugs

The bugs were:
- when in a post-contest phase, the start of that phase was computed
  without taking the extra_time into account;
- the starting_time was allowed to be before the start of the contest;
- when starting_time was not None we assumed it to be in the past, i.e.
  starting_time <= timestamp.
These were all conditions that didn't affect a "normal" contest.
Rewrite the phase computation function

Simplify it and support delay_time (reenabling its tests).
Add delay_time