本文整理汇总了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);
}
示例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));
}
示例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));
}
示例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);
}
示例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));
}
示例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();
}
示例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));
}
示例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));
}
示例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));
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
}
}
}
示例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;
}