本文整理汇总了C#中TimeRange.GetIntersection方法的典型用法代码示例。如果您正苦于以下问题:C# TimeRange.GetIntersection方法的具体用法?C# TimeRange.GetIntersection怎么用?C# TimeRange.GetIntersection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TimeRange
的用法示例。
在下文中一共展示了TimeRange.GetIntersection方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetIntersectionTest
public void GetIntersectionTest() {
var readOnlyTimeRange = new TimeRange(_start, _end);
readOnlyTimeRange.GetIntersection(readOnlyTimeRange).Should().Be(new TimeRange(readOnlyTimeRange));
var timeRange = new TimeRange(_start, _end);
// before
var before1 = timeRange.GetIntersection(new TimeRange(_start.AddHours(-2), _start.AddHours(-1)));
before1.Should().Be.Null();
var before2 = timeRange.GetIntersection(new TimeRange(_start.AddMilliseconds(-1), _start));
before2.Should().Be(new TimeRange(_start));
var before3 = timeRange.GetIntersection(new TimeRange(_start.AddMilliseconds(-1), _start.AddMilliseconds(1)));
before3.Should().Be(new TimeRange(_start, _start.AddMilliseconds(1)));
// after
var after1 = timeRange.GetIntersection(new TimeRange(_end.AddHours(1), _end.AddHours(2)));
after1.Should().Be.Null();
var after2 = timeRange.GetIntersection(new TimeRange(_end, _end.AddMilliseconds(1)));
after2.Should().Be(new TimeRange(_end));
var after3 = timeRange.GetIntersection(new TimeRange(_end.AddMilliseconds(-1), _end.AddMilliseconds(1)));
after3.Should().Be(new TimeRange(_end.AddMilliseconds(-1), _end));
// intersect
timeRange.GetIntersection(timeRange).Should().Be(timeRange);
var itersect1 = timeRange.GetIntersection(new TimeRange(_start.AddMilliseconds(-1), _end.AddMilliseconds(1)));
itersect1.Should().Be(timeRange);
var itersect2 = timeRange.GetIntersection(new TimeRange(_start.AddMilliseconds(1), _end.AddMilliseconds(-1)));
itersect2.Should().Be(new TimeRange(_start.AddMilliseconds(1), _end.AddMilliseconds(-1)));
}