Problem - I have a list of two DateTime Columns in which I want to find the gaps in Time between the two columns where the Dates overlap but there are gaps between the individual dates and hours.
I've been experimenting with the TimePeriod library, but it is not able to discern between the actual gaps within the overlapping periods.
Date Range Example. The start date range is 3/1/2024. The end date range is 6/1/2024 A sample gap exists between 4/1/2024 and 5/1/2024 lines 1 and 5. The time between 1 AM and 5 AM is missing from 4/1 to 5/1.
var organizeCurvePoints = new List<CurveDateOrganizer>();
foreach (var d in AllCurvePointsInRangeCopy)
{
organizeCurvePoints.Add(new CurveDateOrganizer( d.LocalEffectiveTime, d.LocalTerminationTime));
}
organizeCurvePoints.OrderBy(t => t.EffectiveTime);
TimePeriodCollection effectiveHours = new TimePeriodCollection();
effectiveHours.Add(new TimeRange(startDate, endDate));
// Range of Time in PeriodorganizeCurvePoints
ITimePeriodCollection effectivePeriod = new TimePeriodCombiner<TimeRange>().CombinePeriods(effectiveHours);
// Define All Records in Period
TimePeriodCollection curvePeriodDates = new TimePeriodCollection();
foreach (var day in AllCurvePointsInRangeCopy)
{
curvePeriodDates.Add(new TimeRange(day.LocalEffectiveTime, day.LocalTerminationTime));
}
ITimePeriodCollection changePeriods = new TimePeriodCombiner<TimeRange>().CombinePeriods(organizeCurvePoints);
TimePeriodCollection gaps = new TimePeriodCollection();
foreach (ITimePeriod basePeriod in effectiveHours)
{
gaps.AddAll(new TimeGapCalculator<TimeRange>().GetGaps(changePeriods, basePeriod));
}
// Class to Hold Dates
[Serializable]
[DebuggerDisplay("EffectiveTime {EffectiveTime} TerminationTime {TerminationTime}", Name = "{DateOrganizer}")]
public class CurveDateOrganizer
{
private DateTime _effectiveTime;
public DateTime EffectiveTime
{
get => _effectiveTime;
set
{
if (_effectiveTime != value)
{
_effectiveTime = value;
}
}
}
private DateTime _terminationTime;
public DateTime TerminationTime
{
get => _terminationTime;
set
{
if (_terminationTime != value)
{
_terminationTime = value;
}
}
}
public CurveDateOrganizer(DateTime localEffectiveTime, DateTime localTerminationTime)
{
_effectiveTime = localEffectiveTime;
_terminationTime = localTerminationTime;
}
}

ToUnixTimeSeconds()) and then use simple maths to find any gaps.