예제 #1
0
        public string BuildText(IRRuleTokenContainer tokenContainer)
        {
            var resultString = BuildFrequency(tokenContainer);


            var freqValue = (FreqToken.FreqValue)tokenContainer.GetFreq().GetValue();

            if (freqValue == FreqToken.FreqValue.WEEKLY)
            {
                resultString += " " + BuildWeeklyDays(tokenContainer);
            }
            else if (freqValue == FreqToken.FreqValue.MONTHLY && tokenContainer.GetByMontDay() != null)
            {
                resultString += " " + BuildMonthlyOnDay(tokenContainer);
            }
            else if (freqValue == FreqToken.FreqValue.MONTHLY && tokenContainer.GetBySetPos() != null &&
                     tokenContainer.GetByDay() != null)
            {
                resultString += " " + BuildMonthlyOnNumberedDay(tokenContainer);
            }
            else if (freqValue == FreqToken.FreqValue.YEARLY && tokenContainer.GetByMonth() != null &&
                     tokenContainer.GetByMontDay() != null)
            {
                resultString += " " + BuildYearlyOnDay(tokenContainer);
            }
            else if (freqValue == FreqToken.FreqValue.YEARLY && tokenContainer.GetByDay() != null &&
                     tokenContainer.GetBySetPos() != null &&
                     tokenContainer.GetByMonth() != null)
            {
                resultString += " " + BuildYearlyOnNumbered(tokenContainer);
            }
            if (tokenContainer.GetStart() != null)
            {
                var ending = _buildStartDate(tokenContainer);
                if (ending != null)
                {
                    resultString += ", " + ending;
                }
            }

            // Endings
            if (tokenContainer.GetUntil() != null)
            {
                var ending = _buildUntilDateEnding(tokenContainer);
                if (ending != null)
                {
                    resultString += ", " + ending;
                }
            }
            else if (tokenContainer.GetCount() != null)
            {
                var ending = BuildCountEnding(tokenContainer);
                if (ending != null)
                {
                    resultString += ", " + ending;
                }
            }

            return(CapitalizeFirstLetter(resultString.Trim()));
        }
        public void TestByDay()
        {
            IRRuleTokenContainer tokenContainer = tokenizer.Tokenize("FREQ=DAILY;BYDAY=MO,TU,WE,SA");

            Assert.AreEqual(2, tokenContainer.RuleCount());
            Assert.NotNull(tokenContainer.GetByDay());
            Assert.AreEqual(4, ((ByDayToken.DayList)tokenContainer.GetByDay().GetValue()).GetDayList().Count);
        }
예제 #3
0
        public void Merge(IRRuleTokenContainer tokenContainer)
        {
            if (tokenContainer.GetFreq() != null && GetFreq() == null)
            {
                AddOrUpdateToken(tokenContainer.GetFreq());
            }

            if (tokenContainer.GetUntil() != null && GetUntil() == null)
            {
                AddOrUpdateToken(tokenContainer.GetUntil());
            }

            if (tokenContainer.GetCount() != null && GetCount() == null)
            {
                AddOrUpdateToken(tokenContainer.GetCount());
            }

            if (tokenContainer.GetInterval() != null && GetInterval() == null)
            {
                AddOrUpdateToken(tokenContainer.GetInterval());
            }

            if (tokenContainer.GetByDay() != null && GetByDay() == null)
            {
                AddOrUpdateToken(tokenContainer.GetByDay());
            }

            if (tokenContainer.GetByMontDay() != null && GetByMontDay() == null)
            {
                AddOrUpdateToken(tokenContainer.GetByMontDay());
            }

            if (tokenContainer.GetByMonth() != null && GetByMonth() == null)
            {
                AddOrUpdateToken(tokenContainer.GetByMonth());
            }

            if (tokenContainer.GetBySetPos() != null && GetBySetPos() == null)
            {
                AddOrUpdateToken(tokenContainer.GetBySetPos());
            }
        }
        public void TestComplex()
        {
            IRRuleTokenContainer tokenContainer = tokenizer.Tokenize("FREQ=YEARLY;BYDAY=TU;BYSETPOS=1;BYMONTH=4;UNTIL=20181023T220000Z");

            Assert.AreEqual(5, tokenContainer.RuleCount());
            Assert.NotNull(tokenContainer.GetFreq());
            Assert.NotNull(tokenContainer.GetByDay());
            Assert.NotNull(tokenContainer.GetBySetPos());
            Assert.NotNull(tokenContainer.GetByMonth());
            Assert.NotNull(tokenContainer.GetUntil());
            Assert.AreEqual(FreqToken.FreqValue.YEARLY, tokenContainer.GetFreq().GetValue());
        }
예제 #5
0
        /* ---- WEEKLY ---- */

        private string BuildWeeklyDays(IRRuleTokenContainer tokenContainer)
        {
            var byDay = tokenContainer.GetByDay();

            if (byDay == null)
            {
                return("");
            }

            var result = _fragmentTranslator.GetTranslatedFragment(ETranslationFragment.ON) + " ";

            result += _dayListingFormatting.FormatDayListing(((ByDayToken.DayList)byDay.GetValue()).GetDayList().ToList());

            return(result);
        }
예제 #6
0
        private string BuildMonthlyOnNumberedDay(IRRuleTokenContainer tokenContainer)
        {
            var byDayToken    = tokenContainer.GetByDay();
            var bySetPosToken = tokenContainer.GetBySetPos();

            if (byDayToken == null || bySetPosToken == null)
            {
                return("");
            }

            var result = _fragmentTranslator.GetTranslatedFragment(ETranslationFragment.ON);

            result += " " + TranslateSetPosNumber((int)bySetPosToken.GetValue());
            result += " " + _dateFormatting.FormatDay(((ByDayToken.DayList)byDayToken.GetValue()).GetDayList()[0]);

            return(result);
        }