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


C# DateTime.IsBetween方法代码示例

本文整理汇总了C#中System.DateTime.IsBetween方法的典型用法代码示例。如果您正苦于以下问题:C# DateTime.IsBetween方法的具体用法?C# DateTime.IsBetween怎么用?C# DateTime.IsBetween使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.DateTime的用法示例。


在下文中一共展示了DateTime.IsBetween方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: IsBetween_Test

        public void IsBetween_Test()
        {
            const int number = 5;
            number.IsBetween(1, 10).ShouldBeTrue();
            number.IsBetween(1, 5).ShouldBeTrue();
            number.IsBetween(5,10).ShouldBeTrue();
            number.IsBetween(10,20).ShouldBeFalse();

            //DateTime
            var dateTimeValue = new DateTime(2014, 10, 4, 18, 20, 42, 0);
            dateTimeValue.IsBetween(new DateTime(2014, 1, 1), new DateTime(2015, 1, 1)).ShouldBe(true);
            dateTimeValue.IsBetween(new DateTime(2015, 1, 1), new DateTime(2016, 1, 1)).ShouldBe(false);
        }
开发者ID:lizhi5753186,项目名称:BDF,代码行数:13,代码来源:ComparableExtensionsTests.cs

示例2: can_compare_inverted_between

        public void can_compare_inverted_between()
        {
            //interval is from 00:00 -> 10:15 and 14:00 -> 23:59:59
            var startTime = new Time(14);
            var endTime = new Time(10, 15);

            var beforeDate = new DateTime(2011, 5, 3, 9, 30, 0);
            var middleDate = new DateTime(2011, 6, 10, 12, 30, 0);
            var aftereDate = new DateTime(2012, 10, 11, 15, 30, 0);

            Assert.IsFalse(middleDate.IsBetween(startTime, endTime));
            Assert.IsTrue(middleDate.IsBetween(endTime, startTime));
            Assert.IsTrue(beforeDate.IsBetween(startTime, endTime));
            Assert.IsTrue(aftereDate.IsBetween(startTime, endTime));
        }
开发者ID:sihugh,项目名称:DateTimeExtensions,代码行数:15,代码来源:TimeTests.cs

示例3: TestIsBetweenTrue

 public void TestIsBetweenTrue()
 {
     var date = new DateTime(2015,8,20);
     var startDate = new DateTime(2015,8,1);
     var endDate = new DateTime(2015,8,27);
     Assert.IsTrue(date.IsBetween(startDate, endDate, true));
 }
开发者ID:RobPeterson,项目名称:ExtensionsDeluxe,代码行数:7,代码来源:UnitTestDateTimeExtensions.cs

示例4: IsBetween_DateIsNotBetweenTargets

        public void IsBetween_DateIsNotBetweenTargets()
        {
            var DATE1 = new DateTime(2008, 1, 1);
            var DATE2 = new DateTime(2008, 1, 3);
            var TEST_DATE = new DateTime(2008, 1, 4);

            Assert.That(TEST_DATE.IsBetween(DATE1, DATE2), Is.False);
        }
开发者ID:shawnewallace,项目名称:GiveCamp2011,代码行数:8,代码来源:DateTimeExtensionTests.cs

示例5: IsBetween_CanSpecifyArgumentsAsStrings

        public void IsBetween_CanSpecifyArgumentsAsStrings()
        {
            var DATE1 = "1/1/2008";
            var TEST_DATE = new DateTime(2008, 1, 2);
            var DATE2 = "1/3/2008";

            Assert.That(TEST_DATE.IsBetween(DATE1, DATE2));
        }
开发者ID:shawnewallace,项目名称:GiveCamp2011,代码行数:8,代码来源:DateTimeExtensionTests.cs

示例6: DateIsBetweenGivenRange_WithoutTime

        public void DateIsBetweenGivenRange_WithoutTime()
        {
            var dateToCheck = new DateTime(2015, 1, 1);

            var lhsOfRange = new DateTime(2014, 10, 20);
            var rhsOfRange = new DateTime(2015, 2, 1);

            dateToCheck.IsBetween(lhsOfRange, rhsOfRange).Should().BeTrue();
        }
开发者ID:CubicleJockey,项目名称:DateTimeExtensions,代码行数:9,代码来源:ComparisonsTests.cs

示例7: IsBetweenValues

            public void IsBetweenValues()
            {
                DateTime start = new DateTime(2010, 1, 1);
                DateTime end = new DateTime(2010, 1, 3);

                DateTime testValue = new DateTime(2010, 1, 2);

                Assert.True(testValue.IsBetween(start, end));
            }
开发者ID:BilliamBrown,项目名称:Chronos,代码行数:9,代码来源:DateTimeTests.cs

示例8: BetweenTimes

            public void BetweenTimes()
            {
                DateTime start = new DateTime(2010, 1, 1, 1, 0, 0);
                DateTime end = new DateTime(2010, 1, 1, 3, 0, 0);

                DateTime testValue = new DateTime(2010, 1, 1, 2, 0, 0);

                Assert.True(testValue.IsBetween(start, end, true));
            }
开发者ID:BilliamBrown,项目名称:Chronos,代码行数:9,代码来源:DateTimeTests.cs

示例9: can_compare_times

        public void can_compare_times()
        {
            //interval is from 10:15 -> 14:00
            var startTime = new Time(10, 15);
            var endTime = new Time(14);

            var beforeDate = new DateTime(2011, 5, 3, 9, 30, 0);
            var middleDate = new DateTime(2011, 6, 10, 12, 30, 0);
            var aftereDate = new DateTime(2012, 10, 11, 15, 30, 0);

            Assert.IsTrue(beforeDate.IsBefore(startTime));
            Assert.IsTrue(middleDate.IsBetween(startTime, endTime));
            Assert.IsTrue(aftereDate.IsAfter(endTime));

            Assert.IsFalse(aftereDate.IsBefore(startTime));
            Assert.IsFalse(middleDate.IsBetween(endTime, startTime));
            Assert.IsFalse(beforeDate.IsAfter(endTime));
        }
开发者ID:sihugh,项目名称:DateTimeExtensions,代码行数:18,代码来源:TimeTests.cs

示例10: IsBetween_WithDateInterval_IsBefore_IsFalse

		public void IsBetween_WithDateInterval_IsBefore_IsFalse()
		{
			// arrange
			var interval = new DateInterval(new DateTime(2001, 1, 1), new DateTime(2001, 12, 31));
			var date = new DateTime(1999, 5, 14);

			// act
			var result = date.IsBetween(interval);

			// assert
			Assert.That(result, Is.False);
		}
开发者ID:martinjt,项目名称:elmah-loganalyzer,代码行数:12,代码来源:DateTimeExtensionsTests.cs

示例11: IsBetween_AfterEndDate_IsFalse

		public void IsBetween_AfterEndDate_IsFalse()
		{
			// arrange
			var date = new DateTime(1977, 10, 17);

			var startDate = date;
			var endDate = new DateTime(1977, 10, 16);

			// act
			var result = date.IsBetween(startDate, endDate);

			// assert
			Assert.That(result, Is.False);
		}
开发者ID:martinjt,项目名称:elmah-loganalyzer,代码行数:14,代码来源:DateTimeExtensionsTests.cs

示例12: IsBetween_BeforeStartDate_IsFalse

		public void IsBetween_BeforeStartDate_IsFalse()
		{
			// arrange
			var date = new DateTime(1975, 5, 14);

			var startDate = date.AddDays(1);
			var endDate = new DateTime(1977, 10, 16);

			// act
			var result = date.IsBetween(startDate, endDate);

			// assert
			Assert.That(result, Is.False);
		}
开发者ID:martinjt,项目名称:elmah-loganalyzer,代码行数:14,代码来源:DateTimeExtensionsTests.cs

示例13: IsBetween_IsAfterStartDateAndBeforeEndDate_IsTrue

		public void IsBetween_IsAfterStartDateAndBeforeEndDate_IsTrue()
		{
			// arrange
			var date = new DateTime(1975, 5, 14);

			var startDate = date;
			var endDate = new DateTime(1977, 10, 16);
			
			// act
			var result = date.IsBetween(startDate, endDate);

			// assert
			Assert.That(result, Is.True);
		}
开发者ID:martinjt,项目名称:elmah-loganalyzer,代码行数:14,代码来源:DateTimeExtensionsTests.cs

示例14: IsBetweenDateTimeTest

        public void IsBetweenDateTimeTest()
        {
            var i = new DateTime(0);
            while ((i = i.AddTicks(1)) < new DateTime(40))
            {
                var j = new DateTime(0);
                while ((j = j.AddTicks(1)) < new DateTime(40))
                {
                    var k = new DateTime(0);
                    while ((k = k.AddTicks(1)) < new DateTime(60))
                    {
                        var b = k.IsBetween(i, j);

                        bool b2;
                        if (i < j)
                            b2 = (k >= i && k <= j);
                        else
                            b2 = (k >= j && k <= i);

                        Assert.AreEqual(b, b2);
                    }
                }
            }
        }
开发者ID:mateuscezar,项目名称:netgore,代码行数:24,代码来源:IsBetweenTests.cs

示例15: PeriodsOverlap

        public static bool PeriodsOverlap(DateTime aStart, DateTime aEnd, DateTime bStart, DateTime bEnd)
        {
            var bOverlap = false;
            bOverlap |= aStart.IsBetween(bStart, bEnd);
            bOverlap |= aEnd.IsBetween(bStart, bEnd);
            bOverlap |= bStart.IsBetween(aStart, aEnd);
            bOverlap |= bEnd.IsBetween(aStart, aEnd);

            return bOverlap;
        }
开发者ID:HWiese1980,项目名称:HAW-Stundenplan,代码行数:10,代码来源:Helpers.cs


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