public void TestInterval()
        {
            IRRuleTokenContainer tokenContainer = tokenizer.Tokenize("FREQ=DAILY;INTERVAL=1");

            Assert.AreEqual(2, tokenContainer.RuleCount());
            Assert.NotNull(tokenContainer.GetInterval());
            Assert.AreEqual(1, (int)tokenContainer.GetInterval().GetValue());
        }
Пример #2
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 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());
        }
Пример #4
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);
        }