Exemplo n.º 1
0
            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());
            }
Exemplo n.º 2
0
 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());
     }
 }
        public void Listing_7_5()
        {
            DateTime importantDate = new DateTime(2011, 5, 7);

            if (importantDate.IsWeekend())
            {
                WeekendProcessing();
            }
            else
            {
                WeekdayProcessing();
            }
        }
        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);
        }
        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);
        }
 public void Should_DefineWeekend_WhenCalledOn(DateTime date, bool isWeekend)
 {
     date.IsWeekend().Should().Be(isWeekend);
 }
Exemplo n.º 7
0
 public static bool IsWeekDay(this DateTime dt) => !dt.IsWeekend();
Exemplo n.º 8
0
 /// <summary>
 /// Returns whether the DateTime falls on a weekday
 /// </summary>
 /// <param name="datetime">The date to be processed</param>
 /// <returns>Whether the specified date occurs on a weekday</returns>
 public static bool IsWeekDay(this DateTime datetime)
 {
     return(!datetime.IsWeekend());
 }
 public void MondayTest()
 {
     var today = new DateTime(2014, 4, 28); //known Monday
     today.IsWeekend().ShouldBeFalse();
 }
Exemplo n.º 10
0
        /// <summary>
        /// Determines if a specified date is an English national holiday or weekend.
        /// </summary>
        public static bool IsEnglishHoliday(this DateTime date)
        {
            date = date.Date; // drop time.

            if (date.IsWeekend())
            {
                return(true);
            }

            // 1 January - New Year's Day
            if (date == GetActualHolidayDate(new DateTime(date.Year, 1, 1)))
            {
                return(true);
            }

            // 1st Monday in May	Early May Bank Holiday
            if (date == GetEarlyMayBankHoliday(date.Year))
            {
                return(true);
            }

            // Last Monday in May	Spring Bank Holiday
            if (date == GetSpringBankHoliday(date.Year))
            {
                return(true);
            }

            // Last Monday in August	Late Summer Bank Holiday
            if (date == GetLateSummerBankHoliday(date.Year))
            {
                return(true);
            }

            // December 25	Christmas Day
            if (date == GetActualHolidayDate(new DateTime(date.Year, 12, 25)))
            {
                return(true);
            }

            // December 26	Boxing Day
            if (date == GetBoxingDay(date.Year))
            {
                return(true);
            }

            try
            {
                var easterMonday = GetEasterMonday(date.Year);

                // Easter Monday
                if (date == easterMonday)
                {
                    return(true);
                }

                // Good Friday
                if (date == easterMonday.AddDays(-3))
                {
                    return(true);
                }
            }
            catch { /* out of supported range*/ }

            // Additional Holidays
            if (IsAdditionalBankHoliday(date))
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 11
0
            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();
            }
Exemplo n.º 12
0
            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();
            }
Exemplo n.º 13
0
 /// <summary>
 /// Returns whether the DateTime is on a Week Day.
 /// </summary>
 /// <param name="dt">Required. The DateTime to evaluate.</param>
 /// <returns>Returns whether the DateTime is on a Week Day.</returns>
 public static bool IsWeekDay(this System.DateTime dt)
 {
     return(!dt.IsWeekend());
 }
 public void TestIsWeekendSunTrue()
 {
     var date = new DateTime(2015, 8, 23);
     Assert.IsTrue(date.IsWeekend());
 }
 public void TestIsWeekendThursdayFalse()
 {
     var date = new DateTime(2015, 8, 20);
     Assert.IsFalse(date.IsWeekend());
 }
        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());
        }
        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();
        }
Exemplo n.º 18
0
 public bool GoLife(DateTime date)
 {
     if (date.IsWeekend()) {
         Rest ();
         return true;
     } else {
         return false;
     }
 }
 public void SundayTest()
 {
     var lastSunday = new DateTime(2014, 4, 27); // known Sunday
     lastSunday.IsWeekend().ShouldBeTrue();
 }
Exemplo n.º 20
0
 public void MoveTo(int inquiryId, DateTime date)
 {
     var inquiry = repository.Get<Inquiry>(inquiryId);
     if (inquiry == null || date.IsWeekend())
     {
         throw new ModelIsNotValidException();
     }
     inquiry.ReferenceDate = date;
     repository.Save(inquiry);
 }