public void TestUntil()
        {
            IRRuleTokenContainer tokenContainer = tokenizer.Tokenize("FREQ=DAILY;UNTIL=20181023T220000Z");

            Assert.AreEqual(2, tokenContainer.RuleCount());
            Assert.NotNull(tokenContainer.GetUntil());
            Assert.AreEqual(new DateTime(2018, 10, 23, 22, 0, 0),
                            ((ValueWrapper)tokenContainer.GetUntil().GetValue()).getLocalDateTime());
        }
 private void EnsureSingleExistenceUntilCount(IRRuleTokenContainer tokenContainer)
 {
     if (tokenContainer.GetUntil() != null && tokenContainer.GetCount() != null)
     {
         throw new RRuleValidationException("RRule part 'UNTIL' and 'COUNT' are present at the same time");
     }
 }
Пример #3
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()));
        }
Пример #4
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());
        }
Пример #6
0
        /* ---- ENDINGS ---- */

        private string _buildUntilDateEnding(IRRuleTokenContainer pTokenContainer)
        {
            var untilToken = pTokenContainer.GetUntil();

            if (untilToken == null)
            {
                return(null);
            }

            string result = _fragmentTranslator.GetTranslatedFragment(ETranslationFragment.UNTIL);

            result += $" {_dateFormatting.FormatFullDate(((ValueWrapper)untilToken.GetValue()).getLocalDateTime())}";

            return(result);
        }