I have times for start and stop and date of service, like this:
2000-01-01 23:00 23:20
2000-01-01 23:50 00:10
2000-01-01 00:20 00:30
The end time of the second period and the third period need to be moved to the next day, so the result would be:
2000-01-01 23:00 2000-01-01 23:20
2000-01-01 23:50 2000-01-02 00:10
2000-01-02 00:20 2000-01-02 00:30
I can not assume that the entries were entered in the order the records are in (so the
2000-01-01 00:20 00:30 entry may not appear after the other two,
00:20 could mean
2000-01-01 00:20 or
2000-01-02 00:20). Instead, my criterium will be:
Minimize the duration between the minimum start time and the maximum stop time on each day.
In this example:
If I would assume that all times are on 2000-01-01, then the duration between min start time and max end time would be 23 hours (from 00:20 to 23:20). If I move the 2nd and 3rd periods as in my example, the duration between the min start time and max stop time is 1:30 (from 23:00 on 01/01 to 00:30 on 01/02).
Is there some class of algorithms, that would cover this kind of optimization, if not any ideas where to start?