本文整理汇总了C#中DateRange.Count方法的典型用法代码示例。如果您正苦于以下问题:C# DateRange.Count方法的具体用法?C# DateRange.Count怎么用?C# DateRange.Count使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DateRange
的用法示例。
在下文中一共展示了DateRange.Count方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: date_range_iteration_includes_zero_interval
public void date_range_iteration_includes_zero_interval()
{
var startDate = DateTime.SpecifyKind(new DateTime(2010, 02, 09), DateTimeKind.Utc);
var endDate = DateTime.SpecifyKind(new DateTime(2010, 02, 09), DateTimeKind.Utc);
var ob = new DateRange(startDate, endDate);
var expected = (endDate - startDate).Days; // we exclude the last day
var actual = ob.Count();
Assert.That(actual, Is.EqualTo(expected));
}
示例2: GetEnumerator_LengthNotDivisibleByStep_CountMatchesCalculated
public void GetEnumerator_LengthNotDivisibleByStep_CountMatchesCalculated()
{
TimeSpan length = RandomDuration(1, MaxDays);
DateTime start = RandomDate(DateTime.MinValue, DateTime.MaxValue - length);
DateTime end = start + length;
// note that the number of steps is limited to 1000 or fewer
int step = length.Days / Random.Next(4, Math.Max(4, Math.Min(length.Days / 2, 1000)));
// In case range length is under 4, ensure the step is at least 2
if (step < 2) step = 2;
//ensure that step size is not a factor of the length of the range
if (length.Days % step == 0)
{
start += RandomDuration(1, step - 1);
length = end - start;
}
DateRange dateRange = new DateRange(start, end, step);
Assert.AreEqual(length.Days / step + 1, dateRange.Count(), "Iteration count should be (start-end)/step +1");
}
示例3: date_range_is_iterable
public void date_range_is_iterable()
{
var startDate = DateTime.SpecifyKind(new DateTime(2010, 02, 09), DateTimeKind.Utc);
var endDate = DateTime.SpecifyKind(new DateTime(2010, 02, 10), DateTimeKind.Utc);
var ob = new DateRange(startDate, endDate);
var expected = (endDate - startDate).Days;
var actual = ob.Count();
Assert.That(actual, Is.EqualTo(expected));
}
示例4: GetEnumerator_LengthDivisibleByStep_CountMatchesCalculated
public void GetEnumerator_LengthDivisibleByStep_CountMatchesCalculated()
{
TimeSpan length = RandomDuration(1, MaxDays);
DateTime start = RandomDate(DateTime.MinValue, DateTime.MaxValue - length);
DateTime end = start + length;
// note that the number of steps is limited to 1000 or fewer
int step = length.Days / Random.Next(4, Math.Max(4, Math.Min(length.Days / 2, 1000)));
// In case range length is under 4, ensure the step is at least 1
if (step < 1) step = 1;
//ensure that step size is a factor of the length of the range
start += TimeSpan.FromDays(length.Days % step);
DateRange dateRange = new DateRange(start, end, step);
// Range endpoint is inclusive, so must take longo account this extra iteration
Assert.AreEqual(
length.Days / step + 1,
dateRange.Count(),
"Iteration count should be (end-start)/step + 1 where endpoint is included");
}