Example #1
0
        public void EventsOnDateAnnual()
        {
            var offKey = new List <string> {
                "key1"
            };
            var workKey = new List <string> {
                "key2"
            };
            var bothOffWork = new List <string>();

            bothOffWork.AddRange(offKey);
            bothOffWork.AddRange(workKey);
            CalendarDateTime.ClearCalendar();
            CalendarDateTime.AddDateEvent(offKey[0], true, DateTime.Now);
            CalendarDateTime.AddDateEvent(workKey[0], false, DateTime.Now);

            var dayOff  = DateTime.Now.EventsOnDate(false, true).ToList();
            var workday = DateTime.Now.EventsOnDate(true, false).ToList();
            var both    = DateTime.Now.EventsOnDate(true, true).ToList();
            var neither = DateTime.Now.EventsOnDate(false, false).ToList();

            Assert.NotStrictEqual(dayOff, offKey);
            Assert.NotStrictEqual(workday, workKey);
            Assert.Empty(neither);
            Assert.NotStrictEqual(bothOffWork, both);
            Assert.Empty(DateTime.Now.AddDays(1).EventsOnDate(true, true));
        }
Example #2
0
        public void EventsOnDateDate()
        {
            var offKey = new List <string> {
                "dayOf"
            };
            var workKey = new List <string> {
                "dayOn"
            };
            var bothOffWork = new List <string>();

            bothOffWork.AddRange(offKey);
            bothOffWork.AddRange(workKey);
            var date = DateTime.Now;

            CalendarDateTime.ClearCalendar();
            CalendarDateTime.AddYearlyDateEvent(offKey[0], true, date.Month, date.Day, false, false);
            CalendarDateTime.AddYearlyDateEvent(workKey[0], false, date.Month, date.Day, false, false);

            var dayOff  = date.EventsOnDate(false, true).ToList();
            var workday = date.EventsOnDate(true, false).ToList();
            var both    = date.EventsOnDate(true, true).ToList();
            var neither = date.EventsOnDate(false, false).ToList();

            Assert.NotStrictEqual(dayOff, offKey);
            Assert.NotStrictEqual(workday, workKey);
            Assert.Empty(neither);
            Assert.NotStrictEqual(bothOffWork, both);
            Assert.Empty(date.AddDays(1).EventsOnDate(true, true));
        }
Example #3
0
        public void AddMonthlyDayEventYearRange()
        {
            CalendarDateTime.ClearCalendar();
            var        event1Name     = "Workday1";
            const bool event1OffDay   = false;
            var        event1Day      = 12;
            var        firstValidDate = _startTestDate.AddYears(5);
            var        lastValidDate  = _endTestDate.AddYears(-5);

            Assert.Equal(0, CalendarDateTime.CountEvents);
            CalendarDateTime.AddMonthlyDateEvent(event1Name, event1OffDay, event1Day, firstValidDate, lastValidDate);
            Assert.Equal(1, CalendarDateTime.CountMonthlyEvents);
            Assert.Equal(1, CalendarDateTime.CountEvents);

            for (var currentDate = _startTestDate; currentDate <= _endTestDate; currentDate = currentDate.AddDays(1))
            {
                Assert.Equal(currentDate.IsDayOff(), event1OffDay);
                Assert.Equal(currentDate.IsWorkDay(), !event1OffDay);

                var expected = new List <string>();
                if (currentDate.IsBetweenEqual(firstValidDate, lastValidDate) && currentDate.Day == event1Day)
                {
                    expected.Add(event1Name);
                }

                var actual = currentDate.EventsOnDate(true, true);
                Assert.Equal(expected, actual);
            }
        }
Example #4
0
        public void IsOffDay1And3Wednesday()
        {
            var testDayOfWeek = DayOfWeek.Wednesday;

            CalendarDateTime.ClearCalendar();
            CalendarDateTime.AddWeeklyInMonthEvent("FirstThird", true, testDayOfWeek, new List <int> {
                1, 3
            });
            var occurrence   = -99;
            var currentDate  = _startTestDate;
            var dayOfWeekInc = currentDate.DayOfWeek;
            var dateEnd      = _endTestDate;

            while (currentDate <= dateEnd)
            {
                if (currentDate.Day == 1)
                {
                    occurrence   = 1;
                    dayOfWeekInc = currentDate.DayOfWeek;
                }
                else if (currentDate.DayOfWeek == dayOfWeekInc)
                {
                    occurrence++;
                }

                var expected = currentDate.DayOfWeek == testDayOfWeek && (occurrence == 1 || occurrence == 3);
                var actual   = currentDate.IsDayOff();
                Assert.True(expected == actual, "Failed on, " + currentDate);
                currentDate = currentDate.AddDays(1);
            }
        }
Example #5
0
        public void EventDatesMonthlyOfWeekReverseEvent()
        {
            const string    eventName       = "Tango";
            const int       targetWeek      = 2;
            const DayOfWeek targetDayOfWeek = DayOfWeek.Wednesday;

            CalendarDateTime.ClearCalendar();
            CalendarDateTime.AddMonthlyDayOfWeekReverseEvent(eventName, true, targetDayOfWeek, targetWeek, _startTestDate, _endTestDate);
            var actual   = eventName.EventDatesBetween(_startTestDate, _endTestDate);
            var expected = new List <DateTime>();
            int week     = 0;

            for (var date = _endTestDate; date >= _startTestDate; date = date.AddDays(-1))
            {
                if (date.IsLastDayOfMonth())
                {
                    week = 0;
                }

                if (date.DayOfWeek == targetDayOfWeek)
                {
                    week++;
                }

                if (week == targetWeek && date.DayOfWeek == targetDayOfWeek)
                {
                    expected.Add(date);
                }
            }

            expected = expected.OrderBy(s => s).ToList();
            Assert.Equal(expected, actual);
        }
Example #6
0
        public void Remove()
        {
            const string monthlyKey = "monthlyKey";
            const string weekKey    = "WeekKey";
            const string yearlyKey  = "YearlyKey";
            const string dateKey    = "dateKey";

            CalendarDateTime.ClearCalendar();
            CalendarDateTime.AddYearlyDateEvent(yearlyKey, false, 1, 2, false, false);
            CalendarDateTime.AddMonthlyDateEvent(monthlyKey, true, 12);
            CalendarDateTime.AddWeeklyInMonthEvent(weekKey, false, DayOfWeek.Friday);
            CalendarDateTime.AddDateEvent(dateKey, false, DateTime.Now);

            Assert.False(CalendarDateTime.RemoveEvent("nothingRemoved"));
            Assert.True(CalendarDateTime.CountEvents == 4);
            Assert.True(CalendarDateTime.RemoveEvent(weekKey));
            Assert.True(CalendarDateTime.CountEvents == 3);
            Assert.True(CalendarDateTime.RemoveEvent(dateKey));
            Assert.True(CalendarDateTime.CountEvents == 2);
            Assert.True(CalendarDateTime.RemoveEvent(yearlyKey));
            Assert.True(CalendarDateTime.CountEvents == 1);
            Assert.False(CalendarDateTime.RemoveEvent("notHere"));
            Assert.True(CalendarDateTime.CountEvents == 1);
            Assert.True(CalendarDateTime.RemoveEvent(monthlyKey));
            Assert.True(CalendarDateTime.CountEvents == 0);
        }
Example #7
0
        public void AddMonthlyDayOfWeekForwardEventThrowsStartEndInbound()
        {
            const string eventName = "alpha";
            var          start     = new DateTime(DateTime.Now.AddYears(-2).Year, DateTime.Now.AddYears(-2).Month, 1);
            var          end       = DateTime.Now.AddYears(2);

            CalendarDateTime.ClearCalendar();
            CalendarDateTime.AddMonthlyDayOfWeekForwardEvent(eventName, true, DayOfWeek.Friday, 1, start, end);
            bool foundFirstFriday = false;

            for (var currentDate = start; currentDate <= end; currentDate = currentDate.AddDays(1))
            {
                if (currentDate.IsFirstDayOfMonth())
                {
                    foundFirstFriday = false;
                }

                if (!foundFirstFriday && currentDate.DayOfWeek == DayOfWeek.Friday)
                {
                    foundFirstFriday = true;
                    Assert.Contains(eventName, currentDate.EventsOnDate(true, true));
                }
                else
                {
                    Assert.Empty(currentDate.EventsOnDate(true, true));
                }
            }
        }
Example #8
0
 public void AddMonthlyDayOfWeekForwardEventThrowsWeeksForwardInvalid()
 {
     CalendarDateTime.ClearCalendar();
     CalendarDateTime.AddMonthlyDayOfWeekForwardEvent("alpha", true, DayOfWeek.Friday, 1);
     Assert.Throws <ArgumentOutOfRangeException>(() => CalendarDateTime.AddMonthlyDayOfWeekForwardEvent("beta", true, DayOfWeek.Friday, 0));
     Assert.Throws <ArgumentOutOfRangeException>(() => CalendarDateTime.AddMonthlyDayOfWeekForwardEvent("delta", true, DayOfWeek.Friday, -1));
 }
Example #9
0
        public static void AddMonthlyDayOfWeekReverseEventsInRange()
        {
            var eventName = "someName";
            var start     = _startTestDate;
            var end       = _endTestDate.LastDateOfMonth();

            CalendarDateTime.ClearCalendar();

            CalendarDateTime.AddMonthlyDayOfWeekReverseEvent(eventName, true, DayOfWeek.Monday, 1, start, end);             // Last Monday of every month
            var foundLastMonday = false;

            // dateEnd need to seed in as equal or after the last Monday of the month to work (last day of the month works).
            for (var currentDate = end; currentDate >= start; currentDate = currentDate.AddDays(-1))
            {
                if (currentDate.IsLastDayOfMonth())
                {
                    foundLastMonday = false;
                }

                if (!foundLastMonday && currentDate.DayOfWeek == DayOfWeek.Monday)
                {
                    foundLastMonday = true;
                    var actual = currentDate.EventsOnDate(true, true);
                    Assert.Contains(eventName, actual);
                }
                else
                {
                    Assert.Empty(currentDate.EventsOnDate(true, true));
                }
            }
        }
Example #10
0
        public void EventsOnDateYearlyCalculated()
        {
            CalendarDateTime.ClearCalendar();
            CalendarDateTime.AddYearlyCalculatedEvent(HolidayNames.EasterSundayText, true);
            CalendarDateTime.AddYearlyCalculatedEvent(HolidayNames.GoodFridayText, false);

            var goodFridayDate    = new DateTime(2018, 3, 30);
            var goodFridayDayOff  = goodFridayDate.EventsOnDate(false, true);
            var goodFridayWorkday = goodFridayDate.EventsOnDate(true, false);
            var goodFridayBoth    = goodFridayDate.EventsOnDate(true, true);
            var goodFridayNeither = goodFridayDate.EventsOnDate(false, false);

            Assert.Empty(goodFridayDayOff);
            Assert.Contains(CalculatedEventsText.GoodFriday, goodFridayWorkday);
            Assert.Empty(goodFridayNeither);
            Assert.Contains(CalculatedEventsText.GoodFriday, goodFridayBoth);

            var easterDate    = new DateTime(2018, 4, 1);
            var easterDayOff  = easterDate.EventsOnDate(false, true);
            var easterWorkday = easterDate.EventsOnDate(true, false);
            var easterBoth    = easterDate.EventsOnDate(true, true);
            var easterNeither = easterDate.EventsOnDate(false, false);

            Assert.Contains(CalculatedEventsText.EasterSunday, easterDayOff);
            Assert.Empty(easterWorkday);
            Assert.Empty(easterNeither);
            Assert.Contains(CalculatedEventsText.EasterSunday, easterBoth);
        }
Example #11
0
        public void EventsOnDateYearlyReverse()
        {
            var offKey = new List <string> {
                "rev1"
            };
            var workKey = new List <string> {
                "rev2"
            };
            var bothOffWork = new List <string>();

            bothOffWork.AddRange(offKey);
            bothOffWork.AddRange(workKey);
            CalendarDateTime.ClearCalendar();
            CalendarDateTime.AddYearlyDayOfWeekReverseEvent(offKey[0], true, 5, 2, DayOfWeek.Monday);
            CalendarDateTime.AddYearlyDayOfWeekReverseEvent(workKey[0], false, 5, 2, DayOfWeek.Monday);

            var testDate = new DateTime(2018, 5, 21);
            var dayOff   = testDate.EventsOnDate(false, true).ToList();
            var workday  = testDate.EventsOnDate(true, false).ToList();
            var both     = testDate.EventsOnDate(true, true).ToList();
            var neither  = testDate.EventsOnDate(false, false).ToList();

            Assert.NotStrictEqual(dayOff, offKey);
            Assert.NotStrictEqual(workday, workKey);
            Assert.Empty(neither);
            Assert.NotStrictEqual(bothOffWork, both);
            Assert.Empty(testDate.AddDays(1).EventsOnDate(true, true));
        }
Example #12
0
        public void DayOfWeekMonthReverseThrowsYearMin()
        {
            var date = DateTime.MinValue;

            CalendarDateTime.ClearCalendar();
            CalendarDateTime.DayOfWeekMonthReverse(date.Year, date.Month, DayOfWeek.Friday, 1);
            Assert.Throws <ArgumentOutOfRangeException>(() => CalendarDateTime.DayOfWeekMonthReverse(date.Year - 1, date.Month, date.DayOfWeek, 1));
        }
Example #13
0
        public void DayOfWeekMonthForwardThrowsYearMax()
        {
            var date = DateTime.MaxValue;

            CalendarDateTime.ClearCalendar();
            CalendarDateTime.DayOfWeekMonthForward(date.Year, 1, DayOfWeek.Friday, 1);
            Assert.Throws <ArgumentOutOfRangeException>(() => CalendarDateTime.DayOfWeekMonthForward(date.Year + 1, date.Month, date.DayOfWeek, 1));
        }
Example #14
0
        public void AddYearlyDayOfWeekReverseEventWeekDuplicate()
        {
            const string duplicate = "duplicate";

            CalendarDateTime.ClearCalendar();
            CalendarDateTime.AddYearlyDayOfWeekReverseEvent(duplicate, true, 1, 1, DayOfWeek.Monday);
            Assert.Throws <ArgumentException>(() => CalendarDateTime.AddYearlyDayOfWeekReverseEvent(duplicate, false, 1, 1, DayOfWeek.Monday));
        }
Example #15
0
        public void DuplicateKeysThrows()
        {
            const string weekKey = "WeekKey";

            CalendarDateTime.ClearCalendar();
            CalendarDateTime.AddWeeklyInMonthEvent(weekKey, false, DayOfWeek.Friday);
            Assert.Throws <ArgumentException>(() => CalendarDateTime.AddYearlyDateEvent(weekKey, false, 1, 2, false, false));
        }
Example #16
0
        public void AddMonthlyLastDayEventDuplicate()
        {
            const string eventName = "zink";

            CalendarDateTime.ClearCalendar();
            CalendarDateTime.AddMonthlyLastDayEvent(eventName, true);
            Assert.Throws <ArgumentException>(() => CalendarDateTime.AddMonthlyLastDayEvent(eventName, true));
        }
Example #17
0
        public void AddYearlyDayOfWeekReverseEventDuplicate()
        {
            const string dup = "dup";

            CalendarDateTime.ClearCalendar();
            CalendarDateTime.AddYearlyDayOfWeekForwardEvent(dup, true, 10, 1, DayOfWeek.Friday);
            Assert.Throws <ArgumentException>(() => CalendarDateTime.AddYearlyDayOfWeekForwardEvent(dup, true, 11, 1, DayOfWeek.Friday));
        }
Example #18
0
 public void AddMonthlyDayEventThrowsInvalidDay()
 {
     CalendarDateTime.ClearCalendar();
     Assert.Throws <ArgumentOutOfRangeException>(() => CalendarDateTime.AddMonthlyDateEvent("alpha", false, 0));
     CalendarDateTime.AddMonthlyDateEvent("beta", true, 1);
     CalendarDateTime.AddMonthlyDateEvent("delta", true, 31);
     Assert.Throws <ArgumentOutOfRangeException>(() => CalendarDateTime.AddMonthlyDateEvent("gamma", false, 32));
 }
Example #19
0
        public void AddMonthlyDayOfWeekForwardEventThrowsDuplicate()
        {
            const string dup = "duplicate";

            CalendarDateTime.ClearCalendar();
            CalendarDateTime.AddMonthlyDayOfWeekForwardEvent(dup, false, DayOfWeek.Monday, 2);
            Assert.Throws <ArgumentException>(() => CalendarDateTime.AddMonthlyDayOfWeekForwardEvent(dup, true, DayOfWeek.Friday, 1));
        }
Example #20
0
        public void EventDatesBetweenSwap()
        {
            CalendarDateTime.ClearCalendar();
            Holidays.NewYearsDay(true, false, false);
            var expected = Enumerable.Range(_startTestDate.Year, _endTestDate.Year - _startTestDate.Year + 1).Select(s => new DateTime(s, 1, 1));
            var actual   = HolidayNames.NewYearsDayText.EventDatesBetween(_endTestDate.Year, _startTestDate.Year);

            Assert.Equal(expected, actual);
        }
Example #21
0
        public void EventDatesBetweenEmpty()
        {
            CalendarDateTime.ClearCalendar();
            DefinedCalendars.USA.Holidays.ThanksgivingDay(true);
            var expected = new List <DateTime>();
            var actual   = CalendarDateTime.EventDatesBetween(null);

            Assert.Equal(expected, actual);
        }
Example #22
0
        public void IsDayOffAnnualTrue()
        {
            const string may1Name = "A Test";
            var          may1Date = DateTime.Now;

            CalendarDateTime.ClearCalendar();
            CalendarDateTime.AddDateEvent(may1Name, true, may1Date);
            Assert.True(may1Date.IsDayOff());
        }
Example #23
0
        public void EventDatesBetweenEmptyEvent()
        {
            CalendarDateTime.ClearCalendar();
            Calendars.NewYorkStockExchange();
            var expected = new ImmutableArray <DateTime>();
            var actual   = string.Empty.EventDatesBetween(DateTime.MaxValue.Year, DateTime.MinValue.Year);

            Assert.Equal(expected, actual);
        }
Example #24
0
        public void AddWeeklyInMonthEventEventNameDuplicatesThrows()
        {
            const string duplicate = "duplicate";

            CalendarDateTime.ClearCalendar();
            var duplicateDayOfWeeks = DayOfWeek.Friday;

            CalendarDateTime.AddWeeklyInMonthEvent(duplicate, true, duplicateDayOfWeeks);
            Assert.Throws <ArgumentException>(() => CalendarDateTime.AddWeeklyInMonthEvent(duplicate, false, duplicateDayOfWeeks));
        }
Example #25
0
        public void AddWeeklyInMonthEventEventMinZeroThrows()
        {
            // TODO: chanbe to int overload on weeks.
            var weeks = new List <int> {
                1, 0
            };

            CalendarDateTime.ClearCalendar();
            Assert.Throws <ArgumentOutOfRangeException>(() => CalendarDateTime.AddWeeklyInMonthEvent("test", true, DayOfWeek.Friday, weeks));
        }
Example #26
0
        public void AddWeeklyInMonthEventEventMaxSixThrows()
        {
            // TODO: change to single int, remove collection.
            var weeks = new List <int> {
                6, 5
            };

            CalendarDateTime.ClearCalendar();
            Assert.Throws <ArgumentOutOfRangeException>(() => CalendarDateTime.AddWeeklyInMonthEvent("test", true, DayOfWeek.Friday, weeks));
        }
Example #27
0
        public void AddWorkdaysNegToNewYearsNyse()
        {
            CalendarDateTime.ClearCalendar();
            Calendars.NewYorkStockExchange();
            var date       = new DateTime(2016, 1, 26);
            var expected   = new DateTime(2015, 12, 31);
            var addWorkDay = date.AddWorkdays(-16);

            Assert.True(expected == addWorkDay);
        }
Example #28
0
        public void AddWorkdaysNewYearsPlus16PastMartinNyse()
        {
            CalendarDateTime.ClearCalendar();
            Calendars.NewYorkStockExchange();
            var date       = new DateTime(2016, 1, 1);
            var expected   = new DateTime(2016, 1, 26);
            var addWorkDay = date.AddWorkdays(16);

            Assert.True(expected == addWorkDay);
        }
Example #29
0
        public void AddWorkdaysOverNewYearsNyse()
        {
            CalendarDateTime.ClearCalendar();
            Calendars.NewYorkStockExchange();
            var date       = new DateTime(2016, 1, 1);
            var expected   = new DateTime(2016, 1, 4);
            var addWorkDay = date.AddWorkdays(1);

            Assert.True(expected == addWorkDay);
        }
Example #30
0
        public void EventDatesBetweenYearlyDayOfWeekReverse()
        {
            CalendarDateTime.ClearCalendar();
            DefinedCalendars.USA.Holidays.MemorialDay(true);
            var expected = MemorialDays.Select(s => s.Date);
            var fromDate = MemorialDays.Min(s => s.Date);
            var toDate   = MemorialDays.Max(s => s.Date);
            var actual   = DefinedCalendars.USA.HolidayNames.MemorialDayText.EventDatesBetween(fromDate, toDate);

            Assert.NotStrictEqual(expected, actual);
        }