Get breaks from the list of times

I have a list of work items. Each work item has a start and an end time.

So basically it looks like this:

List<Work> works = new List<Work>();
works.Add(new Work(
  new DateTime(2013, 4, 30, 9, 0, 0),
  new DateTime(2013, 4, 30, 11, 0, 0));

Now I want to get the total time. Again, basically this is easy:

09:00-11:00 => 2 hours
13:00-17:00 => 4 hours
----
06:00 hours

This is just the sum.

But now it’s becoming difficult: how do I calculate this amount if I want to extract parallel time?

eg.

09:00-11:00 => 2 hours
10:00-11:30 => 1.5 hours
13:00-17:00 => 4 hours
----
06:30 hours

is 6.5 hours, but the amount is 7.5 hours. The fact that two work items correspond to a time between 10 and 11 hours makes a difference.

How can I solve this for an arbitrary number of work items that can overlap with each other basically in all possible ways (ambient, static overlaps, overlapping ends, including)?

+5
source share
2

(, ), +1 -1 . . , , - , "". , 0 0. .

:

11 - 13, 12-16, 15 - 17, 18 - 19

(11, 1) (12, 1) (13 -1) (15, 1) (16, -1) (17, -1) (18, 1) (19, -1)

(11, 1) (12, 2) (13 1) (15, 2) (16, 1) (17, 0) (18, 1) (19, 0),

(11, 17) (18, 19)

+5

, ( , ). , , :

  • , ,
  • - , , / .

, , . ( , ). , .

+2

All Articles