Improve filtering by time

Now, it is optional to specify start_time or end_time and the query is performed based on whatever is present.