本文整理汇总了C#中TimeRange.Copy方法的典型用法代码示例。如果您正苦于以下问题:C# TimeRange.Copy方法的具体用法?C# TimeRange.Copy怎么用?C# TimeRange.Copy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TimeRange
的用法示例。
在下文中一共展示了TimeRange.Copy方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IntersectionPeriodsTimePeriodTest
public void IntersectionPeriodsTimePeriodTest() {
var now = ClockProxy.Clock.Now;
var timeRange1 = new TimeRange(new DateTime(now.Year, now.Month, 8), new DateTime(now.Year, now.Month, 18));
var timeRange2 = new TimeRange(new DateTime(now.Year, now.Month, 10), new DateTime(now.Year, now.Month, 11));
var timeRange3 = new TimeRange(new DateTime(now.Year, now.Month, 13), new DateTime(now.Year, now.Month, 15));
var timeRange4 = new TimeRange(new DateTime(now.Year, now.Month, 9), new DateTime(now.Year, now.Month, 13));
var timeRange5 = new TimeRange(new DateTime(now.Year, now.Month, 15), new DateTime(now.Year, now.Month, 17));
var timePeriods = new TimePeriodCollection
{
timeRange1,
timeRange2,
timeRange3,
timeRange4,
timeRange5
};
timePeriods.IntersectionPeriods(timeRange1).Count().Should().Be(5);
timePeriods.IntersectionPeriods(timeRange2).Count().Should().Be(3);
timePeriods.IntersectionPeriods(timeRange3).Count().Should().Be(4);
timePeriods.IntersectionPeriods(timeRange4).Count().Should().Be(4);
timePeriods.IntersectionPeriods(timeRange5).Count().Should().Be(3);
var test1 = timeRange1.Copy(new TimeSpan(100, 0, 0, 0).Negate());
var insidePeriods1 = timePeriods.IntersectionPeriods(test1).ToList();
insidePeriods1.Count.Should().Be(0);
var test2 = timeRange1.Copy(new TimeSpan(100, 0, 0, 0));
var insidePeriods2 = timePeriods.IntersectionPeriods(test2).ToList();
insidePeriods2.Count.Should().Be(0);
var test3 = new TimeRange(new DateTime(now.Year, now.Month, 9), new DateTime(now.Year, now.Month, 11));
var insidePeriods3 = timePeriods.IntersectionPeriods(test3).ToList();
insidePeriods3.Count.Should().Be(3);
var test4 = new TimeRange(new DateTime(now.Year, now.Month, 14), new DateTime(now.Year, now.Month, 17));
var insidePeriods4 = timePeriods.IntersectionPeriods(test4).ToList();
insidePeriods4.Count.Should().Be(3);
}
示例2: CopyTest
public void CopyTest() {
var readOnlyTimeRange = new TimeRange(_start, _end);
readOnlyTimeRange.Copy().Should().Be(readOnlyTimeRange);
readOnlyTimeRange.Copy(TimeSpan.Zero).Should().Be(readOnlyTimeRange);
var timeRange = new TimeRange(_start, _end);
timeRange.Start.Should().Be(_start);
timeRange.End.Should().Be(_end);
var noMoveTimeRange = timeRange.Copy(TimeSpan.Zero);
noMoveTimeRange.Start.Should().Be(timeRange.Start);
noMoveTimeRange.End.Should().Be(timeRange.End);
noMoveTimeRange.Duration.Should().Be(timeRange.Duration);
noMoveTimeRange.Should().Be(timeRange);
var forwardOffset = new TimeSpan(2, 30, 15);
var forwardTimeRange = timeRange.Copy(forwardOffset);
forwardTimeRange.Start.Should().Be(_start.Add(forwardOffset));
forwardTimeRange.End.Should().Be(_end.Add(forwardOffset));
forwardTimeRange.Duration.Should().Be(duration);
var backwardOffset = new TimeSpan(-1, 10, 30);
var backwardTimeRange = timeRange.Copy(backwardOffset);
backwardTimeRange.Start.Should().Be(_start.Add(backwardOffset));
backwardTimeRange.End.Should().Be(_end.Add(backwardOffset));
backwardTimeRange.Duration.Should().Be(duration);
}