Допустим, у меня большой интервал
Код: Выделить всё
LargeInterval interval = new LargeInterval
{
StartPeriod = DateTime.Today,
EndPeriod = DateTime.Today.AddYears(1),
};
Код: Выделить всё
public class LargeInterval
{
public DateTime StartPeriod { get; set; }
public DateTime EndPeriod { get; set; }
}
Код: Выделить всё
public class SmallInterval
{
public string From{ get; set; }
public string To { get; set; }
}
Код: Выделить всё
SmallInterval s1 = new SmallInterval
{
From = "2024-05-01"
End = "2024-07-03"
}
Код: Выделить всё
SmallInterval s2 = new SmallInterval
{
From = "2024-08-01"
End = "2024-10-03"
}
Код: Выделить всё
SmallIntervalКод: Выделить всё
intervalКод: Выделить всё
LargeInterval. Что-то вроде:
DateTime.Today until "2024-04-30"
Код: Выделить всё
"2024-07-04" until "2024-07-31"
Код: Выделить всё
"2024-10-04" until DateTime.Today.AddYears(1).AddDays(-1)
Код: Выделить всё
DateTime startPeriod = interval.StartPeriod;
DateTime endPeriod = interval.EndPeriod;
IEnumerable existingPeriodsIntersectingTheNewPeriod = smallIntervals.Where(x => x.From = startPeriod).OrderBy(x => x.From);
foreach (var stsp in existingPeriodsIntersectingTheNewPeriod)
{
/// handling all scenarios
}
Источник: https://stackoverflow.com/questions/781 ... r-interval
Мобильная версия