collectTasks function to collect tasks for given hours