public class OrganizingTime
{
public OrganizingTime(List<Betime> time)
{
m_timeList = time;
}
private List<Betime> m_timeList;
public List<Betime> TimeList
{
get { return m_timeList; }
}
private void Order()
{
m_timeList = m_timeList.OrderBy(i => i.BeginTime).ToList();
m_timeList = m_timeList.OrderBy(i => i.EndTime).ToList();
}
public void Union()
{
Order();
for (int i = 0; i < m_timeList.Count - 1; i++)
{
int j = i + 1;
if (m_timeList[i].EndTime >= m_timeList[j].BeginTime)
{
if (m_timeList[i].EndTime >= m_timeList[j].EndTime)
{
m_timeList[j] = m_timeList[i];
}
else
{
m_timeList[j].BeginTime = m_timeList[i].BeginTime;
}
m_timeList[i] = null;
}
else
{
i++;
}
}
}
}
public class Betime
{
public DateTime BeginTime { get; set; }
public DateTime EndTime { get; set; }
}