public void Next_ReturnsPreviousFridayProperly()
        {
            var friday = new DateTime(2009, 7, 17, 1, 0, 0, 0, DateTimeKind.Local);
            var reallyPreviousFriday = new DateTime(2009, 7, 10, 1, 0, 0, 0, DateTimeKind.Local);
            var previousFriday       = friday.Previous(DayOfWeek.Friday);

            DateAssert.AreEqual(reallyPreviousFriday, previousFriday);
        }
        public void NextYear_ReturnsTheSameDateButNextYear()
        {
            var birthday = new DateTime(1976, 12, 31, 17, 0, 0, 0, DateTimeKind.Local);
            var nextYear = birthday.NextYear();
            var expected = new DateTime(1977, 12, 31, 17, 0, 0, 0, DateTimeKind.Local);

            DateAssert.AreEqual(expected, nextYear);
        }
        public void ChangeTime_Millisecond_SimpleTests(int value)
        {
            var toChange = new DateTime(2008, 10, 25, 0, 0, 0, 0, DateTimeKind.Local);

            var expected = new DateTime(2008, 10, 25, 0, 0, 0, value, DateTimeKind.Local);

            DateAssert.AreEqual(expected, toChange.SetTime(0, 0, 0, value));
        }
        public void Next_ReturnsNextFridayProperly()
        {
            var friday           = new DateTime(2009, 7, 10, 1, 0, 0, 0, DateTimeKind.Local);
            var reallyNextFriday = new DateTime(2009, 7, 17, 1, 0, 0, 0, DateTimeKind.Local);
            var nextFriday       = friday.Next(DayOfWeek.Friday);

            DateAssert.AreEqual(reallyNextFriday, nextFriday);
        }
        public void PreviousYear_IfPreviousYearDoesNotHaveTheSameDayInTheSameMonthThenCalculateHowManyDaysIsMissingAndAddThatToTheLastDayInTheSameMonthPreviousYear()
        {
            var someBirthday = new DateTime(2012, 2, 29, 17, 0, 0, 0, DateTimeKind.Local);
            var previousYear = someBirthday.PreviousYear();
            var expected     = new DateTime(2011, 3, 1, 17, 0, 0, 0, DateTimeKind.Local);

            DateAssert.AreEqual(expected, previousYear);
        }
        public void NextYear_IfNextYearDoesNotHaveTheSameDayInTheSameMonthThenCalculateHowManyDaysIsMissingAndAddThatToTheLastDayInTheSameMonthNextYear()
        {
            var someBirthday = new DateTime(2008, 2, 29, 17, 0, 0, 0, DateTimeKind.Local);
            var nextYear     = someBirthday.NextYear();
            var expected     = new DateTime(2009, 3, 1, 17, 0, 0, 0, DateTimeKind.Local);

            DateAssert.AreEqual(expected, nextYear);
        }
        public void PreviousYear_ReturnsTheSameDateButPreviousYear()
        {
            var birthday     = new DateTime(1976, 12, 31, 17, 0, 0, 0, DateTimeKind.Local);
            var previousYear = birthday.PreviousYear();
            var expected     = new DateTime(1975, 12, 31, 17, 0, 0, 0, DateTimeKind.Local);

            DateAssert.AreEqual(expected, previousYear);
        }
        public void ChangeTime_Hour_SimpleTests(int value)
        {
            var toChange = new DateTime(2008, 10, 25, 0, 0, 0, 0, DateTimeKind.Local);

            var result   = toChange.SetTime(value);
            var expected = new DateTime(2008, 10, 25, value, 0, 0, 0, DateTimeKind.Local);

            DateAssert.AreEqual(expected, result);
        }
        public void BasicTests()
        {
            var now = DateTime.Now;

            DateAssert.AreEqual(new DateTime(now.Year, now.Month, now.Day, 23, 59, 59, 999, DateTimeKind.Local), DateTime.Now.EndOfDay(), " End of the day wrong");
            DateAssert.AreEqual(new DateTime(now.Year, now.Month, now.Day, 0, 0, 0, 0, DateTimeKind.Local), DateTime.Now.BeginningOfDay(), "Start of the day wrong");

            var firstBirthDay = new DateTime(1977, 12, 31, 17, 0, 0, 0, DateTimeKind.Local);

            DateAssert.AreEqual(firstBirthDay + new TimeSpan(1, 0, 5, 0, 0), firstBirthDay + 1.Days() + 5.Minutes());

            DateAssert.AreEqual(now + TimeSpan.FromDays(1), now.NextDay());
            DateAssert.AreEqual(now - TimeSpan.FromDays(1), now.PreviousDay());

            DateAssert.AreEqual(now + TimeSpan.FromDays(7), now.WeekAfter());
            DateAssert.AreEqual(now - TimeSpan.FromDays(7), now.WeekEarlier());

            Assert.AreEqual(new DateTime(2009, 1, 1, 0, 0, 0, 0, DateTimeKind.Local), new DateTime(2008, 12, 31, 0, 0, 0, DateTimeKind.Local).Add(1.Days()));
            Assert.AreEqual(new DateTime(2009, 1, 2, 0, 0, 0, 0, DateTimeKind.Local), new DateTime(2009, 1, 1, 0, 0, 0, 0, DateTimeKind.Local).Add(1.Days()));

            var sampleDate = new DateTime(2009, 1, 1, 13, 0, 0, 0, DateTimeKind.Local);

            DateAssert.AreEqual(new DateTime(2009, 1, 1, 12, 0, 0, 0, DateTimeKind.Local), sampleDate.Noon());
            DateAssert.AreEqual(new DateTime(2009, 1, 1, 0, 0, 0, 0, DateTimeKind.Local), sampleDate.Midnight());

            Assert.AreEqual(3.Days() + 3.Days(), 6.Days());
            Assert.AreEqual(102.Days() - 3.Days(), 99.Days());

            Assert.AreEqual(24.Hours(), 1.Days());

            sampleDate = new DateTime(2008, 1, 1, 0, 0, 0, 0, DateTimeKind.Local);
            DateAssert.AreEqual(3.Days().Since(sampleDate), sampleDate + 3.Days());

            var saturday = new DateTime(2008, 10, 25, 12, 0, 0, DateTimeKind.Local);

            DateAssert.AreEqual(new DateTime(2008, 11, 1, 12, 0, 0, DateTimeKind.Local), saturday.Next(DayOfWeek.Saturday));

            DateAssert.AreEqual(new DateTime(2008, 10, 18, 12, 0, 0, DateTimeKind.Local), saturday.Previous(DayOfWeek.Saturday));

            // ReSharper disable UnusedVariable
            var nextWeek = DateTime.Now + 1.Weeks();

            var tomorrow                    = DateTime.Now + 1.Days();
            var yesterday                   = DateTime.Now - 1.Days();
            var changedHourTo14H            = DateTime.Now.SetHour(14);
            var todayNoon                   = DateTime.Now.Noon();
            var tomorrowNoon                = DateTime.Now.NextDay().Noon();
            var fiveDaysAgo                 = 5.Days().Ago();
            var twoDaysFromNow              = 2.Days().FromNow();
            var nextYearSameDateAsTodayNoon = 1.Years().FromNow().Noon();

            var twoWeeksFromNow = 2.Weeks().FromNow();

            // ReSharper restore UnusedVariable
        }
Beispiel #10
0
        public void Ago_FromFixedDateTime_Tests(int agoValue)
        {
            var originalPointInTime = new DateTime(1976, 12, 31, 17, 0, 0, 0, DateTimeKind.Local);

            DateAssert.AreEqual(agoValue.Years().Before(originalPointInTime), originalPointInTime.AddYears(-agoValue));
            DateAssert.AreEqual(agoValue.Months().Before(originalPointInTime), originalPointInTime.AddMonths(-agoValue));
            DateAssert.AreEqual(agoValue.Weeks().Before(originalPointInTime), originalPointInTime.AddDays(-agoValue * DAYS_PER_WEEK));
            DateAssert.AreEqual(agoValue.Days().Before(originalPointInTime), originalPointInTime.AddDays(-agoValue));

            DateAssert.AreEqual(agoValue.Hours().Before(originalPointInTime), originalPointInTime.AddHours(-agoValue));
            DateAssert.AreEqual(agoValue.Minutes().Before(originalPointInTime), originalPointInTime.AddMinutes(-agoValue));
            DateAssert.AreEqual(agoValue.Seconds().Before(originalPointInTime), originalPointInTime.AddSeconds(-agoValue));
            DateAssert.AreEqual(agoValue.Milliseconds().Before(originalPointInTime), originalPointInTime.AddMilliseconds(-agoValue));
            DateAssert.AreEqual(agoValue.Ticks().Before(originalPointInTime), originalPointInTime.AddTicks(-agoValue));
        }
        public void From_FromFixedDateTime_Tests(int value)
        {
            var originalPointInTime = new DateTime(1976, 12, 31, 17, 0, 0, 0, DateTimeKind.Local);

            DateAssert.AreEqual(value.Years().From(originalPointInTime), originalPointInTime.AddYears(value));
            DateAssert.AreEqual(value.Months().From(originalPointInTime), originalPointInTime.AddMonths(value));
            DateAssert.AreEqual(value.Weeks().From(originalPointInTime), originalPointInTime.AddDays(value * DaysPerWeek));
            DateAssert.AreEqual(value.Days().From(originalPointInTime), originalPointInTime.AddDays(value));

            DateAssert.AreEqual(value.Hours().From(originalPointInTime), originalPointInTime.AddHours(value));
            DateAssert.AreEqual(value.Minutes().From(originalPointInTime), originalPointInTime.AddMinutes(value));
            DateAssert.AreEqual(value.Seconds().From(originalPointInTime), originalPointInTime.AddSeconds(value));
            DateAssert.AreEqual(value.Milliseconds().From(originalPointInTime), originalPointInTime.AddMilliseconds(value));
            DateAssert.AreEqual(value.Ticks().From(originalPointInTime), originalPointInTime.AddTicks(value));
        }
        public void FirstDayOfWeek_FirstDayOfWeekIsSunday(int value)
        {
            var ci             = Thread.CurrentThread.CurrentCulture;
            var currentCulture = new CultureInfo("en-AU")
            {
                DateTimeFormat =
                {
                    FirstDayOfWeek = DayOfWeek.Sunday
                }
            };

            Thread.CurrentThread.CurrentCulture = currentCulture;
            var expected = new DateTime(2011, 1, 23, 0, 0, 0, DateTimeKind.Local);

            DateAssert.AreEqual(expected, new DateTime(2011, 1, value, 0, 0, 0, DateTimeKind.Local).FirstDayOfWeek());
            Thread.CurrentThread.CurrentCulture = ci;
        }
        public void NextQuarter_LastDay_SetsTheDayToLastDayOfQuarter()
        {
            var expected = new DateTime(2002, 6, 30, 3, 5, 6, DateTimeKind.Local);

            DateAssert.AreEqual(expected.BeginningOfDay(), 1.Quarters().From(new DateTime(2002, 1, 10, 4, 5, 6, DateTimeKind.Local).LastDayOfQuarter().BeginningOfDay()));
        }
        public void PreviousMonth_NextMonthDoesntHaveThatManyDays()
        {
            var expected = new DateTime(2013, 2, 28, 06, 40, 20, 5, DateTimeKind.Local);

            DateAssert.AreEqual(expected, new DateTime(2013, 1, 31, 06, 40, 20, 5, DateTimeKind.Local).NextMonth());
        }
        public void NextMonth_BasicTest()
        {
            var expected = new DateTime(2013, 1, 5, 06, 40, 20, 5, DateTimeKind.Local);

            DateAssert.AreEqual(expected, new DateTime(2012, 12, 5, 06, 40, 20, 5, DateTimeKind.Local).NextMonth());
        }
        public void PreviousMonth_BasicTest()
        {
            var expected = new DateTime(2009, 12, 20, 06, 40, 20, 5, DateTimeKind.Local);

            DateAssert.AreEqual(expected, new DateTime(2010, 1, 20, 06, 40, 20, 5, DateTimeKind.Local).PreviousMonth());
        }
        public void SubtractBusinessDays_Negative()
        {
            var expected = new DateTime(2009, 7, 13, 0, 0, 0, DateTimeKind.Local);

            DateAssert.AreEqual(expected, new DateTime(2009, 7, 9, 0, 0, 0, DateTimeKind.Local).SubtractBusinessDays(-2));
        }
        public void AddBusinessDays_AdsDaysProperlyWhenThereIsWeekendAhead()
        {
            var expected = new DateTime(2009, 7, 13, 0, 0, 0, DateTimeKind.Local);

            DateAssert.AreEqual(expected, new DateTime(2009, 7, 9, 0, 0, 0, DateTimeKind.Local).AddBusinessDays(2));
        }
        public void SubtractBusinessDays_SubtractsDaysProperlyWhenThereIsWeekend()
        {
            var expected = new DateTime(2009, 7, 9, 0, 0, 0, DateTimeKind.Local);

            DateAssert.AreEqual(expected, new DateTime(2009, 7, 13, 0, 0, 0, DateTimeKind.Local).SubtractBusinessDays(2));
        }
        public void LastDayOfQuarter_Q4_SetsTheDayToLastDayOfQuarter()
        {
            var expected = new DateTime(2002, 12, 31, 4, 5, 6, DateTimeKind.Local);

            DateAssert.AreEqual(expected.BeginningOfDay(), new DateTime(2002, 11, 22, 12, 12, 12, DateTimeKind.Local).LastDayOfQuarter().BeginningOfDay());
        }
        public void LastDayOfMonth_SetsTheDayToLastDayInThatMonth()
        {
            var expected = new DateTime(2002, 1, 31, 17, 05, 01, DateTimeKind.Local);

            DateAssert.AreEqual(expected, new DateTime(2002, 1, 1, 17, 05, 01, DateTimeKind.Local).LastDayOfMonth());
        }
        public void FirstDayOfQuarter_Q4_SetsDayToFirstDay()
        {
            var expected = new DateTime(2002, 10, 1, 7, 8, 9, DateTimeKind.Local);

            DateAssert.AreEqual(expected.BeginningOfDay(), new DateTime(2002, 11, 22, 12, 12, 12, DateTimeKind.Local).FirstDayOfQuarter().BeginningOfDay());
        }
Beispiel #23
0
        public void AddBusinessDays_AdsDaysProperlyWhenThereIsPartialWeekendAhead()
        {
            var expected = new DateTime(2009, 7, 20, 0, 0, 0, DateTimeKind.Local);

            DateAssert.AreEqual(expected, new DateTime(2009, 7, 17, 0, 0, 0, DateTimeKind.Local).AddBusinessDays(2, DateTimeExtensions.WeekEnd.Sunday));
        }
        public void PreviousQuarter_LastDay_SetsTheDayToLastDayOfQuarter()
        {
            var expected = new DateTime(2001, 12, 31, 3, 5, 6, DateTimeKind.Local);

            DateAssert.AreEqual(expected.BeginningOfDay(), 1.Quarters().Ago(new DateTime(2002, 1, 10, 4, 5, 6, DateTimeKind.Local).LastDayOfQuarter().BeginningOfDay()));
        }
        public void FirstDayOfMonth_SetsTheDayToOne()
        {
            var expected = new DateTime(2002, 12, 1, 17, 05, 01, DateTimeKind.Local);

            DateAssert.AreEqual(expected, new DateTime(2002, 12, 17, 17, 05, 01, DateTimeKind.Local).FirstDayOfMonth());
        }
        public void At_SetsHourAndMinutesAndMillisecondsProperly()
        {
            var expected = new DateTime(2002, 12, 17, 18, 06, 02, 03, DateTimeKind.Local);

            DateAssert.AreEqual(expected, new DateTime(2002, 12, 17, 17, 05, 01, DateTimeKind.Local).At(18, 06, 02, 03));
        }