dynamically calculate beginning time, end time and duration