本文整理汇总了C#中System.DateTime.IsWeekend方法的典型用法代码示例。如果您正苦于以下问题:C# DateTime.IsWeekend方法的具体用法?C# DateTime.IsWeekend怎么用?C# DateTime.IsWeekend使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.DateTime
的用法示例。
在下文中一共展示了DateTime.IsWeekend方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DateOnWeekend_IsTrue
public void DateOnWeekend_IsTrue()
{
DateTime date = new DateTime(2015, 11, 1); // Sunday
Assert.True(date.IsWeekend());
date = new DateTime(2015, 11, 7);
Assert.True(date.IsWeekend());
}
示例2: IsWeekendTest
public void IsWeekendTest()
{
DateTime dt = new DateTime(2015, 5, 2);
Assert.True(dt.IsWeekend());
dt = new DateTime(2015, 5, 3);
Assert.True(dt.IsWeekend());
for (int i = 0; i < 5; i++)
{
dt = new DateTime(2015, 5, 4 + i);
Assert.False(dt.IsWeekend());
}
}
示例3: Listing_7_5
public void Listing_7_5()
{
DateTime importantDate = new DateTime(2011, 5, 7);
if (importantDate.IsWeekend())
{
WeekendProcessing();
}
else
{
WeekdayProcessing();
}
}
示例4: IsWeekend_WithWeekendDayDate_ExpectTrue
public void IsWeekend_WithWeekendDayDate_ExpectTrue(
int year,
int month,
int day,
DayOfWeek expectedDayOfWeek)
{
// Arrange
DateTimeExtensions.MinValid = new DateTime(year, 1, 1);
DateTimeExtensions.MaxValid = new DateTime(year, 12, 31);
var classUnderTest = new DateTime(year, month, day, 23, 53, 59);
Assert.AreEqual(expectedDayOfWeek, classUnderTest.DayOfWeek);
// Act
var actual = classUnderTest.IsWeekend();
// Assert
Assert.AreEqual(true, actual);
}
示例5: SundayTest
public void SundayTest()
{
var lastSunday = new DateTime(2014, 4, 27); // known Sunday
lastSunday.IsWeekend().ShouldBeTrue();
}
示例6: MondayTest
public void MondayTest()
{
var today = new DateTime(2014, 4, 28); //known Monday
today.IsWeekend().ShouldBeFalse();
}
示例7: IsWeekendTest
public void IsWeekendTest()
{
var sunday = new DateTime(2012, 4, 1);
Assert.AreEqual(DayOfWeek.Sunday, sunday.DayOfWeek);
Assert.IsTrue(sunday.IsWeekend());
var monday = sunday.AddDays(1);
Assert.AreEqual(DayOfWeek.Monday, monday.DayOfWeek);
Assert.IsFalse(monday.IsWeekend());
var tuesday = sunday.AddDays(2);
Assert.AreEqual(DayOfWeek.Tuesday, tuesday.DayOfWeek);
Assert.IsFalse(tuesday.IsWeekend());
var wednesday = sunday.AddDays(3);
Assert.AreEqual(DayOfWeek.Wednesday, wednesday.DayOfWeek);
Assert.IsFalse(wednesday.IsWeekend());
var thursday = sunday.AddDays(4);
Assert.AreEqual(DayOfWeek.Thursday, thursday.DayOfWeek);
Assert.IsFalse(thursday.IsWeekend());
var friday = sunday.AddDays(5);
Assert.AreEqual(DayOfWeek.Friday, friday.DayOfWeek);
Assert.IsFalse(friday.IsWeekend());
var saturday = sunday.AddDays(6);
Assert.AreEqual(DayOfWeek.Saturday, saturday.DayOfWeek);
Assert.IsTrue(saturday.IsWeekend());
}
示例8: IsWorkdayShouldSuccessWhenHolydayCalculatorsIsNullAndDayIsNotWeekend
public void IsWorkdayShouldSuccessWhenHolydayCalculatorsIsNullAndDayIsNotWeekend()
{
var year = 2012;
var monday = new DateTime(year, 4, 2);
Assert.AreEqual(DayOfWeek.Monday, monday.DayOfWeek);
var mondayIsWeekend = monday.IsWeekend();
var mondayIsWorkday = monday.IsWorkDay(null);
Assert.False(mondayIsWeekend);
Assert.True(mondayIsWorkday);
}
示例9: Should_DefineWeekend_WhenCalledOn
public void Should_DefineWeekend_WhenCalledOn(DateTime date, bool isWeekend)
{
date.IsWeekend().Should().Be(isWeekend);
}
示例10: GoLife
public bool GoLife(DateTime date)
{
if (date.IsWeekend()) {
Rest ();
return true;
} else {
return false;
}
}
示例11: Should_check_is_weekend
public void Should_check_is_weekend()
{
//arrange
var date1 = new DateTime(2013, 03, 30, 0, 0, 0);
var date2 = new DateTime(2013, 03, 28, 0, 0, 0);
//act
var res1 = date1.IsWeekend();
var res2 = date2.IsWeekend();
//assert
res1.Should().BeTrue();
res2.Should().BeFalse();
}
示例12: Yes
public void Yes()
{
var saturday = new DateTime(2015, 11, 7);
saturday.IsWeekend().Should().BeTrue();
var sunday = new DateTime(2015, 11, 8);
sunday.IsWeekend().Should().BeTrue();
}
示例13: No
public void No()
{
var monday = new DateTime(2015, 11, 2);
monday.IsWeekend().Should().BeFalse();
var tuesday = new DateTime(2015, 11, 3);
tuesday.IsWeekend().Should().BeFalse();
var wednsdey = new DateTime(2015, 11, 3);
wednsdey.IsWeekend().Should().BeFalse();
var thursday = new DateTime(2015, 11, 3);
thursday.IsWeekend().Should().BeFalse();
var friday = new DateTime(2015, 11, 3);
friday.IsWeekend().Should().BeFalse();
}
示例14: TestIsWeekendSunTrue
public void TestIsWeekendSunTrue()
{
var date = new DateTime(2015, 8, 23);
Assert.IsTrue(date.IsWeekend());
}
示例15: TestIsWeekendThursdayFalse
public void TestIsWeekendThursdayFalse()
{
var date = new DateTime(2015, 8, 20);
Assert.IsFalse(date.IsWeekend());
}