public void TestFreq()
        {
            IRRuleTokenContainer tokenContainer = tokenizer.Tokenize("FREQ=DAILY");

            Assert.AreEqual(1, tokenContainer.RuleCount());
            Assert.NotNull(tokenContainer.GetFreq());
            Assert.AreEqual(FreqToken.FreqValue.DAILY, tokenContainer.GetFreq().GetValue());
        }
        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());
        }
        public void TestMergeDoNotOverride()
        {
            IRRuleTokenContainer firstPart  = tokenizer.Tokenize("FREQ=WEEKLY;INTERVAL=1");
            IRRuleTokenContainer secondPart = tokenizer.Tokenize("FREQ=YEARLY;INTERVAL=1;BYMONTHDAY=1;BYSETPOS=1");

            // Merge secondPart into firstPart
            firstPart.Merge(secondPart);

            Assert.NotNull(firstPart.GetFreq());
            Assert.AreNotEqual(secondPart.GetFreq(), firstPart.GetFreq());
            Assert.AreNotEqual(secondPart.GetInterval(), firstPart.GetInterval());
        }
 private void EnsureFreqExistence(IRRuleTokenContainer tokenContainer)
 {
     if (tokenContainer.GetFreq() == null)
     {
         throw new RRuleValidationException("Required rrule part 'FREQ' is not present");
     }
 }
Esempio n. 5
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()));
        }
Esempio n. 6
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 TestMergeSimple()
        {
            IRRuleTokenContainer firstPart  = tokenizer.Tokenize("FREQ=WEEKLY;INTERVAL=1");
            IRRuleTokenContainer secondPart = tokenizer.Tokenize("FREQ=YEARLY;INTERVAL=1;BYMONTHDAY=1;BYSETPOS=1");

            // Merge secondPart into firstPart
            firstPart.Merge(secondPart);

            Assert.NotNull(firstPart.GetFreq());
            Assert.NotNull(firstPart.GetByMontDay());
            Assert.NotNull(firstPart.GetBySetPos());
            Assert.NotNull(firstPart.GetByMontDay());

            Assert.AreEqual(secondPart.GetByMontDay(), firstPart.GetByMontDay());
            Assert.AreEqual(secondPart.GetBySetPos(), firstPart.GetBySetPos());
        }
Esempio n. 8
0
        /* ---- FREQUENCY ---- */

        private string  BuildFrequency(IRRuleTokenContainer tokenContainer)
        {
            var freqValue = (FreqToken.FreqValue)tokenContainer.GetFreq().GetValue();

            int interval = 1;

            if (tokenContainer.GetInterval() != null)
            {
                interval = (int)tokenContainer.GetInterval().GetValue();
            }

            string value = null;

            if (interval == 1)
            {
                switch (freqValue)
                {
                case FreqToken.FreqValue.DAILY:
                    value = _fragmentTranslator.GetTranslatedFragment(ETranslationFragment.DAILY);
                    break;

                case FreqToken.FreqValue.WEEKLY:
                    value = _fragmentTranslator.GetTranslatedFragment(ETranslationFragment.WEEKLY);
                    break;

                case FreqToken.FreqValue.MONTHLY:
                    value = _fragmentTranslator.GetTranslatedFragment(ETranslationFragment.MONTHLY);
                    break;

                case FreqToken.FreqValue.YEARLY:
                    value = _fragmentTranslator.GetTranslatedFragment(ETranslationFragment.YEARLY);
                    break;
                }
            }
            else
            {
                value = _fragmentTranslator.GetTranslatedFragment(ETranslationFragment.EVERY) + " " + interval + " ";
                switch (freqValue)
                {
                case FreqToken.FreqValue.DAILY:
                    value += _fragmentTranslator.GetTranslatedFragment(ETranslationFragment.DAYS);
                    break;

                case FreqToken.FreqValue.WEEKLY:
                    value += _fragmentTranslator.GetTranslatedFragment(ETranslationFragment.WEEKS);
                    break;

                case FreqToken.FreqValue.MONTHLY:
                    value += _fragmentTranslator.GetTranslatedFragment(ETranslationFragment.MONTHS);
                    break;

                case FreqToken.FreqValue.YEARLY:
                    value += _fragmentTranslator.GetTranslatedFragment(ETranslationFragment.YEARS);
                    break;
                }
            }

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

            return(value);
        }