calculate maxtime