Calculate location and number of intersections between multiple date/time ranges?
Posted
by Patricker
on Stack Overflow
See other posts from Stack Overflow
or by Patricker
Published on 2010-04-29T15:18:53Z
Indexed on
2010/04/29
18:57 UTC
Read the original article
Hit count: 272
I need to calculate the location of intersections between multiple date ranges, and the number of overlapping intersections. Then I need to show which date/time ranges overlap each of those intersecting sections. It is slightly more complicated than that so I'll do my best to explain by providing an example. I am working in VB.Net, but C# examples are acceptable as well as I work in both.
We have several high risk tasks that involve the same system. Below I have three example jobs named HR1/2/3/4 with start and end date/times.
- HR1 {1/6/2010 10:00 - 1/6/2010 15:00}
- HR2 {1/6/2010 11:00 - 1/6/2010 18:00}
- HR3 {1/6/2010 12:00 - 1/6/2010 14:00}
- HR4 {1/6/2010 18:00 - 1/6/2010 20:00}
What I want the end result to be is shown below. I am having trouble describing it any way but by example.
- HRE1 {1/6/2010 10:00 - 1/6/2010 11:00} - Intersects 1
- {End Time Split 1, for readability only, not needed in solution}
- HRE1 {1/6/2010 11:00 - 1/6/2010 12:00} - Intersects 2
- HRE2 {1/6/2010 11:00 - 1/6/2010 12:00} - Intersects 2
- {End Time Split 2, for readability only, not needed in solution}
- HRE1 {1/6/2010 12:00 - 1/6/2010 14:00} - Intersects 3
- HRE2 {1/6/2010 12:00 - 1/6/2010 14:00} - Intersects 3
- HRE3 {1/6/2010 12:00 - 1/6/2010 14:00} - Intersects 3
- {End Time Split 3, for readability only, not needed in solution}
- HRE1 {1/6/2010 14:00 - 1/6/2010 15:00} - Intersects 2
- HRE2 {1/6/2010 14:00 - 1/6/2010 15:00} - Intersects 2
- {End Time Split 4, for readability only, not needed in solution}
- HRE2 {1/6/2010 15:00 - 1/6/2010 18:00} - Intersects 1
- {End Time Split 5, for readability only, not needed in solution}
- HR4 {1/6/2010 18:00 - 1/6/2010 20:00} - Intersects 1
Any help would be greatly appreciated.
© Stack Overflow or respective owner