Пример #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 TestByMonth()
        {
            IRRuleTokenContainer tokenContainer = tokenizer.Tokenize("FREQ=DAILY;BYMONTH=12");

            Assert.AreEqual(2, tokenContainer.RuleCount());
            Assert.NotNull(tokenContainer.GetByMonth());
            Assert.AreEqual(12, tokenContainer.GetByMonth().GetValue());
        }
Пример #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
        /* ---- YEARLY ---- */
        private string BuildYearlyOnDay(IRRuleTokenContainer tokenContainer)
        {
            var byMonthToken    = tokenContainer.GetByMonth();
            var byMonthDayToken = tokenContainer.GetByMontDay();

            if (byMonthDayToken == null || byMonthToken == null)
            {
                return("");
            }

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

            result += " " + _dateFormatting.FormatMonthDay(new DateTime(DateTime.Now.Year, (int)byMonthToken.GetValue(), (int)byMonthDayToken.GetValue()));

            return(result);
        }
Пример #6
0
        private string BuildYearlyOnNumbered(IRRuleTokenContainer tokenContainer)
        {
            var byDayToken    = tokenContainer.GetByDay();
            var bySetPosToken = tokenContainer.GetBySetPos();
            var byMonthToken  = tokenContainer.GetByMonth();

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

            var result = _fragmentTranslator.GetTranslatedFragment(ETranslationFragment.ON) + " " + TranslateSetPosNumber((int)bySetPosToken.GetValue());

            result += " " + _dateFormatting.FormatDay(((ByDayToken.DayList)byDayToken.GetValue()).GetDayList()[0]);
            result += " " + _fragmentTranslator.GetTranslatedFragment(ETranslationFragment.OF);
            result += " " + _dateFormatting.FormatMonth((int)byMonthToken.GetValue());

            return(result);
        }