public UnionTE Create()
        {
            var union = new UnionTE();

            var quarters = EnumExtensions.GetFlags(_event.QuarterlyOptions);
            var quarterlyIntervals = EnumExtensions.GetFlags(_event.QuarterlyIntervalOptions);
            var monthlyIntervals = EnumExtensions.GetFlags(_event.MonthlyIntervalOptions);
            var daysOfWeek = EnumExtensions.GetFlags(_event.DaysOfWeekOptions);

            foreach (QuarterEnum quarter in quarters)
            {
                foreach (QuarterlyIntervalEnum qInt in quarterlyIntervals)
                {
                    foreach (MonthlyIntervalEnum mInt in monthlyIntervals)
                    {
                        foreach (DayOfWeekEnum day in daysOfWeek)
                        {
                            var dayInQuarter = new DayInQuarterTE(quarter, qInt, mInt, day);
                            union.Add(dayInQuarter);
                        }
                    }
                }
            }
            return union;
        }
예제 #2
0
        public void CanMatchMonthWithMatrix()
        {
            // build a matrix:
            DayInQuarterTE te1 = new DayInQuarterTE(QuarterEnum.First, QuarterlyIntervalEnum.First, MonthlyIntervalEnum.First, DayOfWeekEnum.Fri);
            var mqMatrix = te1.BuildMonthQuarterMatrix();

            // test that we find quarters & intervals based on arbitrary dates
            DateTime dt;
            int expectedMonth;
            int ourMonth;
            int monthCounter = 1;
            for (int i = 0; i <= 3; i++) // quarters
            {
                for (int j = 0; j <= 2; j++) // quarter intervals (months)
                {
                    expectedMonth = (i * 3) + j; // zero-based month for the matrix coordinates we are at
                    dt = new DateTime(DateTime.Now.Year, monthCounter, 15);
                    ourMonth = (int)mqMatrix.GetValue(i, j) + 1; // zero-based

                    Assert.IsTrue(ourMonth == dt.Month, string.Format("date match wrong: {0}", dt.ToString("f")));

                    monthCounter++;
                }
            }
        }
예제 #3
0
        public void CanFindSetTEInMatrix()
        {
            // te for Q1, Month 1 (Jan == 0)
            DayInQuarterTE te1 = new DayInQuarterTE(QuarterEnum.First, QuarterlyIntervalEnum.First, MonthlyIntervalEnum.First, DayOfWeekEnum.Fri);
            var mqMatrix = te1.BuildMonthQuarterMatrix();

            int expectedMonth = (int)mqMatrix.GetValue(0, 0);
            Assert.IsTrue(expectedMonth == 0, "expect Jan (0)");

            // now loop 'em all:
            DayInQuarterTE te = null;
            QuarterEnum quarter;
            QuarterlyIntervalEnum quarterInterval;
            int monthCounter = 0;

            for (int i = 0; i <= 3; i++)
            {
                for (int j = 0; j <= 2; j++)
                {
                    quarter = (QuarterEnum)i;
                    quarterInterval = (QuarterlyIntervalEnum)j;
                    te = new DayInQuarterTE(quarter, quarterInterval, MonthlyIntervalEnum.First, DayOfWeekEnum.Fri);

                    expectedMonth = (int)mqMatrix.GetValue(i, j);
                    Assert.IsTrue(expectedMonth == monthCounter, string.Format("expected {0}, returned {1}", monthCounter, expectedMonth));

                    monthCounter++;
                }
            }
        }
예제 #4
0
        public void MonthQuarterMatrixConstructed()
        {
            // arbitrary TE
            DayInQuarterTE te = new DayInQuarterTE(QuarterEnum.First, QuarterlyIntervalEnum.First, MonthlyIntervalEnum.First, DayOfWeekEnum.Fri);
            var mqMatrix = te.BuildMonthQuarterMatrix();

            // check all of the values of the matrix: length1 == quarters, length2 == quarter intervals (months 1, 2, 3)
            Assert.IsTrue((int)mqMatrix.GetValue(0, 0) == 0, "expect Month 0 (Jan)");
            Assert.IsTrue((int)mqMatrix.GetValue(0, 1) == 1, "expect Month 1 (Feb)");
            Assert.IsTrue((int)mqMatrix.GetValue(0, 2) == 2, "expect Month 2 (Mar)");

            Assert.IsTrue((int)mqMatrix.GetValue(1, 0) == 3, "expect Month 3 (Apr)");
            Assert.IsTrue((int)mqMatrix.GetValue(1, 1) == 4, "expect Month 4 (May)");
            Assert.IsTrue((int)mqMatrix.GetValue(1, 2) == 5, "expect Month 5 (Jun)");

            Assert.IsTrue((int)mqMatrix.GetValue(2, 0) == 6, "expect Month 6 (Jul)");
            Assert.IsTrue((int)mqMatrix.GetValue(2, 1) == 7, "expect Month 7 (Aug)");
            Assert.IsTrue((int)mqMatrix.GetValue(2, 2) == 8, "expect Month 8 (Sep)");

            Assert.IsTrue((int)mqMatrix.GetValue(3, 0) == 9, "expect Month 9 (Oct)");
            Assert.IsTrue((int)mqMatrix.GetValue(3, 1) == 10, "expect Month 10 (Nov)");
            Assert.IsTrue((int)mqMatrix.GetValue(3, 2) == 11, "expect Month 11 (Dec)");
        }