当前位置: 首页>>代码示例>>C#>>正文


C# DateRange.Count方法代码示例

本文整理汇总了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));
        }
开发者ID:NextITCorp,项目名称:ScheduleEvents,代码行数:12,代码来源:DateExpressionTests.cs

示例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");
        }
开发者ID:webappsuk,项目名称:CoreLibraries,代码行数:22,代码来源:DateRangeTests.cs

示例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));
        }
开发者ID:NextITCorp,项目名称:ScheduleEvents,代码行数:12,代码来源:DateExpressionTests.cs

示例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");
        }
开发者ID:webappsuk,项目名称:CoreLibraries,代码行数:22,代码来源:DateRangeTests.cs


注:本文中的DateRange.Count方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。