TRQ-2845: Fixed tmp_time math in mom_main main loop

Fixed tmp_time math
Moved the logic to a function
Wrote a unit test